when lookup returns multiple rows - accomidate in same row

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
muascdev
Charter Member
Charter Member
Posts: 51
Joined: Tue Oct 10, 2006 5:48 pm

when lookup returns multiple rows - accomidate in same row

Post by muascdev »

my requirement is as follows, i have an input file, and on one of the fields , i need to do a look up, which will return 3 rows always, with 1 column ineach row, now i need to add these 3 vaules from 3 rows into an output file into 3 diff column on the same row. we are using lookup stage in parallel, but dont know how to proceed further.

ex : input file
123,234,2345
look up on 234 returns 12
13
14
output should be:
123,234,2345,12,13,14

appreciate any help
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Get the three rows, pass it through a transformer where you need to utilize stage variables to do this vertical pivoting.
Something to the effect of, compare present key with previous rows key, if same, concatenate the row values with each other. Pass it through remove duplicate stage and retain the last record which will have all the three values.
For more info on the method, search on "vertical pivot"
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Could you not also do the pivot in the source query that builds the lookup? Especially if you know it will 'always be three', return a single record there with the three fields rather than all the shenanigans to do it afterwards.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply