Multiple Rows to One Row (Vertical Pivoting)

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
rohit_mca2003
Participant
Posts: 41
Joined: Wed Oct 08, 2008 9:19 am

Multiple Rows to One Row (Vertical Pivoting)

Post by rohit_mca2003 »

Hi,
I have a requirement to pivot the multiple rows into a single row. I have input data as below:

Input Data:
-------------
Id Fname Sname Section Ques Ans
--------------------------------------------------------------------
100 Sam Roy S1 Q11 A11
100 Sam Roy S1 Q12 A12
100 Sam Roy S1 Q13 A13
100 Sam Roy S2 Q21 A21
100 Sam Roy S2 Q22 A22


I like output data as follows in one row and different columns:
-----------------------------------------------------------------------
100 Sam Roy S1 Q11 A11 Q12 A12 Q13 A13 S2 Q21 A21 Q22 A22


Could you please help me to resolve this.

Regards.
Mike
Premium Member
Premium Member
Posts: 1021
Joined: Sun Mar 03, 2002 6:01 pm
Location: Tampa, FL

Post by Mike »

No need to post the same question more than once. This question gets asked a lot here. Try the search function. An exact match on vertical pivot turns up 154 hits.

Mike
rohit_mca2003
Participant
Posts: 41
Joined: Wed Oct 08, 2008 9:19 am

Multiple Rows to One Row (Vertical Pivoting)

Post by rohit_mca2003 »

Thanks for all your replies.
I have searched the topics but I have not got any suitable reply for my input set of data.

If you see the input set it has two pivot columns ID and SECTION. It would be greatful if anyone can provide solution to this example.

Input Data:
-------------
Id Fname Sname Section Ques Ans
--------------------------------------------------------------------
100 Sam Roy S1 Q11 A11
100 Sam Roy S1 Q12 A12
100 Sam Roy S1 Q13 A13
100 Sam Roy S2 Q21 A21
100 Sam Roy S2 Q22 A22


I like output data as follows in one row and different columns:
-----------------------------------------------------------------------
100 Sam Roy S1 Q11 A11 Q12 A12 Q13 A13 S2 Q21 A21 Q22 A22
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Just generalize to two pivot keys from the solutions given. For example use additional stage variables.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply