INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Join 2 coulms in a same File

Join 2 coulms in a same File

(OP)
I am having some problem with joining 2 columns.
for example

C1         C2     C3
----------------------
date1      A01    -
date2      A04   A02
date3      A01   A05
date4      A03   A02

I want to have an output as

C1          C2
-------------------
date1       A01  
       
date2       A04
date2       A02

date3       A01
date3       A05

date4       A03
date4       A02

Can someone help me out ?
 

RE: Join 2 coulms in a same File

There are a few ways to do this. First off, you say you're JOINING 2 columns. Are the sources of these columns 2 different files, or do you just have one file, with (effectively) 3 columns?

If the first option (2 files), then consider using the MORE command, rather than the JOIN, to merge the data.

If the latter, then, assuming your data volume isn't too great, extract one column into a separate file, and THEN use the MORE command.

If the dat volume is considerable, there are more advanced techniques to get what you want, but let's hold off on them until you respond.

RE: Join 2 coulms in a same File

(OP)
All the 3 columns exist in the same file .
Can you tell me how to extract the column and use the MORE COMMAND?

RE: Join 2 coulms in a same File

The MORE command allows you to effectively CONCATENATE outsput data from 2 or more files. It requires all fields referenced to exist in each file (possibly through a DEFINE). The first request establishes the fields and output. It ends with MORE, instead of END. You then reference the 'next' file, as FILE xxx (xxx being the filename). The original request is automatically applied (hence the need for all fields to exist), but any selections can be added. When the last request terminates with END, the concatenated datas is used to produce the output.

In your example, you could extract some of the data (i.e. fields C1 and C3) into a HOLD file, and use MORE to combine that with the original data. Here's what it might look like:

CODE

TABLE FILE filename
PRINT C3 AS 'C2' BY C1 ON TABLE HOLD
ON TABLE SET ASNAMES ON
END
This extracts the C3 data, and calls it C2 in the HOLD file. Then, you use MORE:

CODE

TABLE FILE filename
PRINT C2 BY C1
MORE
FILE HOLD
END

RE: Join 2 coulms in a same File

(OP)
Yes it worked out fine.Thanks.But if we have to combine 3 columns like C2,C3, C4 BY C1 then how we are supposed to combine ?Can we add one more File in the MORE Command??

 

RE: Join 2 coulms in a same File

Sure. Per the doc:

"There is no limit to the number of subrequests, other than available memory."

just end every subrequest (every file after the first) with a MORE statement, and end the FINAL subrequest with an END.

RE: Join 2 coulms in a same File

(OP)
Thank you very much Sir.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close