Expanding record based on Key

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
JPalatianos
Premium Member
Premium Member
Posts: 306
Joined: Wed Jun 21, 2006 11:41 am

Expanding record based on Key

Post by JPalatianos »

Hi,
I have an input table with 2 columns: ITEM_ID and TXN_TYPE with values for example as follows:
ITEM_ID TXN_TYPE
1 A
1 B
2 A
3 A
3 B
3 C

I want to convert this so that there is one row per ITEM_ID, with columns for each occurrence from the original table. For example:
ITEM_ID TXN_TYPE1 TXN_TYPE2 TXN_TYPE3
1 A B
2 A
3 A B C

Is this easily doable in datastage?
Thanks -- John
JPalatianos
Premium Member
Premium Member
Posts: 306
Joined: Wed Jun 21, 2006 11:41 am

Post by JPalatianos »

Hi,
Can someone move this to the enterprise forum. We are running 8.0.1 enterprise edition at our shop.
Thanks - - John
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

I certainly can if you are looking for a PX answer, but you marked it for Server and if that's the solution you are looking for we're in the right place.
-craig

"You can never have too many knives" -- Logan Nine Fingers
kab123
Participant
Posts: 92
Joined: Tue May 18, 2004 4:05 pm

Post by kab123 »

Do a Lookup with same table and map the column if the values only if found and then write the output to a hash file. If you really care for the order of the columns then you may have to do a sort later and then write to the output hash file.
Thanks
JPalatianos
Premium Member
Premium Member
Posts: 306
Joined: Wed Jun 21, 2006 11:41 am

Post by JPalatianos »

Sorry...I am looking for a parallel answer. I accidentally left the default of "Server".
Thanks - - John
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Moved and updated.
-craig

"You can never have too many knives" -- Logan Nine Fingers
soumya5891
Participant
Posts: 152
Joined: Mon Mar 07, 2011 6:16 am

Post by soumya5891 »

Considering one thing that TXN_TYPE is either A or B or C

1. Use a filter stage to separate out three links l1,l2,l3,l4(say)
2. In l1 use TXN_TYPE="A" and rename the col TXN_TYPE as TXN_TYPE_1
3. In l2 use TXN_TYPE="B" and rename the col TXN_TYPE as TXN_TYPE_2
4. In l3 use TXN_TYPE="C" and rename the col TXN_TYPE as TXN_TYPE_3
5. In l4 use TXN_TYPE="A" or TXN_TYPE="B" or TXN_TYPE="C".And then perform a remove duplicate on ITEM_ID.
6. Now perform a left outer join between 5,2,3,4,keeping 5 as left link.

Hope you will get your desired output.Just try and let me know in case of any concern.
Soumya
Post Reply