Page 1 of 1

How to Change Columns into ROWS

Posted: Fri Dec 21, 2007 8:14 am
by horserider
I have a source file that has 18 columns, 2 of them make Primary Key. I want to convert some of the columns in a row to multiple rows. Example below.

INPUT SOURCE FILE

PKey CustNum Add_1 Tel_1 Zip_1 Add_2 Tel_2 Zip_2 Add_3 Zip_3 Tel_3 Total_Amt Total_Rebate

OUTOUT FILE DESIRED AS

PKey CustNum Add_1 Tel_1 Zip_1 Tot_Amt Tot_Rebate
PKey CustNum Add_2 Tel_2 Zip_2 Tot_Amt Tot_Rebate
PKey CustNum Add_3 Tel_3 Zip_3 Tot_Amt Tot_Rebate

Basically for 3 set of Address Tel and Zip in 1 ROW, I want to create 3 rows that has each set in 1 row?

Any way to get this done in Parallel Job?

Posted: Fri Dec 21, 2007 8:21 am
by chulett
Pivot stage.

Posted: Fri Dec 21, 2007 9:45 am
by uegodawa
Use a Pivot stage and define the OUTPUT of Pivot as follows
1. PKey
2.CustNum
3. Address
4. Telephone
5. Zip
6. Total_Amt
7.Total_Rebate

Use the following derivations;
Address : Add_1,Add_2, Add_3
Telephone : Tel_1 , Tel_2, Tel_3
Zip : Zip_1,Zip_2, Zip_3

Posted: Fri Dec 21, 2007 10:56 am
by relati
You could accomplish this using a Transformer stage with multiple output links, each output containing the desired fields.

Posted: Fri Dec 21, 2007 1:51 pm
by horserider
Yes I can very well do that. The only problem is if the columns I have to make into rows is too much then I will have too many transformers. Pivot will work best for me.

Posted: Thu Dec 27, 2007 7:26 am
by jshurak
can the pivot stage do the opposite. I have a query that returns 11 rows in one column. I'd like to split those up into 11 columns and one row.

Posted: Thu Dec 27, 2007 7:39 am
by chulett
Allegedly 'yes' in version 8.x but otherwise - no.

Posted: Thu Dec 27, 2007 8:18 am
by jshurak
is there any stage that can do that?

Posted: Thu Dec 27, 2007 8:50 am
by chulett
Typically using manual 'aggregation' with stage variable concatenation in a Transformer. Search for 'vertical pivot' for discussions on the subject.

Posted: Thu Dec 27, 2007 9:26 am
by jshurak
thanks!