splitsingle row into multiple rows

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

narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

splitsingle row into multiple rows

Post by narsi1111 »

I have requirment like this my inputs structure is

loc-key,code_key,year,totsales,,jan,feb.....dec but out put ssould be in this format


loc_key,codekey,year,jan,tosales

lockey,codkey,year,feb,totsales

Using Transformer how to implment please can any one help me

Thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Pivot stage does columns to rows, check it out.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Any special reason why you want to use the transformer for this?
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

Hi

Post by narsi1111 »

yes i don't have pivot stage please can tell me how to implment
with out using pivot

Thanks

:-)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Far simpler to install the stage and use that, then it would be all automagic. I don't recall it being one of the 'optional' plug-ins but seems like it must be if you really don't have it. :?

Check the FAQ forum, there is a post there on creating multiple rows from a single row with a couple of different techniques, from what I recall. If you really want to play the game that way, give it a read.
-craig

"You can never have too many knives" -- Logan Nine Fingers
narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

Post by narsi1111 »

You too smart please da.... why don't you recall for me how to implment without using piviot.. i tried whole fourum but no technique all are telling use pivot. please help me da if you are able to recall it's really helpful for me...

:-):-)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why should I write it all up again when it's already in the FAQ Forum as I noted? Here is a direct link:

viewtopic.php?t=88639

Start there and let us know if you have any questions after you've tried to implement it.

And in your spare time, install the Pivot stage.
-craig

"You can never have too many knives" -- Logan Nine Fingers
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

A simple routine can do the trick as well using the methodoligy embedded in Craigs post. If you love awk, a single liner awk is enough.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

Post by narsi1111 »

Thanks for your great help
narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

Post by narsi1111 »

do u have that awk code if u have please help me
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

Did you try to do it yourself buddy. Give Roy's methodology a shot. Also if you dont know awk it will be hard for you to even understand the code i give you. Try to do it yourself, if nothing works out at the end then post again and i will give you the awk code.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

splitsingle row into multiple rows

Post by narsi1111 »

Really you so sweet man i like you so much the way which you answering for my small doubts


please send me that awk code first i have to resolve these issue i will start learning qwk tomorrow onwards please send me that code


Thanks

:-):-):)
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

:? :? :?
Really... :shock:
Anyways, heres the code.

Code: Select all

awk 'BEGIN{FS=",";OFS=","}{for(i=5;i<=NF;i++) print $1,$2,$3,$i,$4}' yourfile.txt > newfile.txt
The new file will have one row split into 12 rows the way you want it.
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

Post by narsi1111 »

Thanks
for my gr8 friend

:-)
narsi1111
Participant
Posts: 20
Joined: Mon Jan 15, 2007 12:01 am

Hi

Post by narsi1111 »

please look into these below code iam not able genrate new key

even a_key-------->column having null ,it should genrate key. do u think technically any problem in below code iam not able genrate new keys

If isNULL(a_key) Then (DSLink10.max_loc_Key + KeyMgtGetNextValue(DSJobStartTimestamp)) Else DSLink5.SK_LOCATION_KEY


Thanks

:) :) :( :( :?
Post Reply