multi lines --> single line ?

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
htrisakti3
Charter Member
Charter Member
Posts: 36
Joined: Thu Jun 10, 2004 11:22 pm

multi lines --> single line ?

Post by htrisakti3 »

if I have single column source that have 0,1,..N rows -- how can I transform into single line? ie:

source
AAA
BBB
CCC

output: AAA BBB CCC
tcj
Premium Member
Premium Member
Posts: 98
Joined: Tue Sep 07, 2004 6:57 pm
Location: QLD, Australia
Contact:

Post by tcj »

The pivot stage should provide you with what you want.
Don't know if you need to install it as a plugin or not.

You should be able to read more information about the pivot stage in the plugin documentation. Should be in the docs folder in the datastage client folder on your pc.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

What you are asking for is a vertical pivot. The Pivot stage performs horizontal pivot (one line to many), but definitely does not perform vertical pivots.

Several techniques are available, depending on exact circumstances. For example is there a small, finite number of columns to be generated in each cycle? Are the input data sorted?

Search the forum for an exact match on "vertical pivot" to learn more.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
tcj
Premium Member
Premium Member
Posts: 98
Joined: Tue Sep 07, 2004 6:57 pm
Location: QLD, Australia
Contact:

Post by tcj »

Sorry my mistake. Didn't have a copy of Datastage to double check if the pivot stage did both pivots. :oops:
Gokul
Participant
Posts: 74
Joined: Wed Feb 23, 2005 10:58 pm
Location: Mumbai

Post by Gokul »

what type is the source is it?
1> If the source is Oracle then u can try the below query as user defined query and get the required result.

Code: Select all

  select max(decode(rownum,1,dname))||max(decode(rownum,2,dname))||max(decode(rownum,3,dname))  C  from dept
2> If the source is sequential and u r writing in a sequential file ,try with Line Termination set to none on the general tab of the o/p sequential file and delimeter set to ','.

(I tried this , the input rows were
AA
BB
CC

When i viewed the o/p file in the notepad the result was
"AA","BB","CC"
)

Thanks,
Gokul
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I believe a more generic solution is needed, Gokul. For example

AA 1
BB 1
CC 1
AA 2
BB 2
CC 2

should yield

AA BB CC 1
AA BB CC 2

Your approach does not handle this; it can only ever generate one output row.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Gokul
Participant
Posts: 74
Joined: Wed Feb 23, 2005 10:58 pm
Location: Mumbai

Post by Gokul »

Hi Ray,

Since the question was

if I have single column source that have 0,1,..N rows -- how can I transform into single line? ie:

source
AAA
BBB
CCC

output: AAA BBB CCC
I have consider a single source column. As always we hope to get a generic solution from you. :wink:

Gokul
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You already did. :wink:

Vertical pivot.

Search is your friend.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
djm
Participant
Posts: 68
Joined: Wed Mar 02, 2005 3:42 am
Location: N.Z.

Post by djm »

One option may be the Unix "paste" command. You can use it to roll-up multiple lines of data into a single line (I'm assuming that there are a consistent number of rows per set to be rolled up).

I don't have a Unix command session on hand to try this but some variation on

Code: Select all

paste -s -d '\t\t\n' filename > anotherfile
should roll-up repeating three rows of data into one row. Then take your input from "anotherfile" (columns would be tab-separated) and simply pick-out the columns you want.

This would address the generic question posed by ray.

David.

edit: replace uglier example with cleaner example, post running a "man paste".
Post Reply