trouble with pivot

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
datastagenewbie
Participant
Posts: 64
Joined: Tue Sep 23, 2008 9:54 am

trouble with pivot

Post by datastagenewbie »

Hi I am trying to use pivot and am not getting the desired output, i searched the forum but none helped :cry:
Here is my input
Col1, Col2
--------------
a,1
a,2
a,3
a,4
b,1
b,5
b,6

And the output I want is

Col
-----
a
1
2
3
4
b
1
5
6


By using pivot I am getting
a
1
a
2
a
3
a
4
b
1
b
5
b
6


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

Post by chulett »

That's not really a pivot. You could "pre-process" the data into a form that the pivot stage would like however, I would assume. Or perhaps do this all with stage variables in the transformer. :?

I'm short on time (and brains atm) so will leave the gory details to others...
-craig

"You can never have too many knives" -- Logan Nine Fingers
datastagenewbie
Participant
Posts: 64
Joined: Tue Sep 23, 2008 9:54 am

Post by datastagenewbie »

I used Sorter , and then in the transformer I used this expression.
If keyChange=1 then Col1 : char(10): Col2 Else Col2

Got me the desired results. :-)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Very nice. 8)
-craig

"You can never have too many knives" -- Logan Nine Fingers
agpt
Participant
Posts: 151
Joined: Sun May 16, 2010 12:53 am

Post by agpt »

can u pls explain the syntax:

If keyChange=1 then Col1 : char(10): Col2 Else Col2

what it does exactly?

Sorry to ask this but I am a new learner so....
anbu
Premium Member
Premium Member
Posts: 596
Joined: Sat Feb 18, 2006 2:25 am
Location: india

Post by anbu »

a,1
a,2
a,3
a,4
b,1
b,5
b,6
If you set the option Create Key Change column in sort to true then sort creates a column keyChange and output of sort is
a,1,1
a,2,0
a,3,0
a,4,0
b,1,1
b,5,0
b,6,0
If keyChange is one then add a newline char between Col1 and Col2 else just Col2

Code: Select all

If keyChange=1 then Col1 : char(10): Col2 Else Col2 
You are the creator of your destiny - Swami Vivekananda
agpt
Participant
Posts: 151
Joined: Sun May 16, 2010 12:53 am

Post by agpt »

Thanks
Post Reply