Page 1 of 1

Split one column into multiple columns

Posted: Tue Mar 12, 2013 12:48 am
by surajspatil
I have data in one column which is separated by comma which look like below
1st row
MTCN,Rec Date,Payee Name,Sender Name,Rec Acct,TID,OPID,NETID,Orig-Pay-NAID,Cnl-Acct,TID,OPID, PRD,Prin,Charges,Tot fee,Gross,Del Svc,Comment
2nd row
`973XXXX80,03-06-13,JOSE ALFREDO\GUTIERREZ VASQUEZ,JOSE ALFREDO\GUTIERREZ VASQUEZ,VST121707,AE91,001,00690,MXV01,VKC358297,W244. ........

I need to ignore 1 row and from 2nd row i need to split data in to multiple data in separate columns

Posted: Tue Mar 12, 2013 2:03 am
by ray.wurlod
Read with a Sequential File stage with First Line is Column Names set to True. Read the whole row into a single column, whose data type is a sufficiently large VarChar.

Parse the data using a Column Import stage or a Transfomer stage using Field() functions.

Split one column into multiple columns

Posted: Tue Mar 12, 2013 3:02 am
by surajspatil
Ray,
as said in my first line.. data is there in table with one column and data residing is delimited by comma, i tried to use Filed function in transformer to split one column into multiple columns but i need to ignore the one row which has column names.. i hope you got what i'm saying.

Posted: Tue Mar 12, 2013 3:13 am
by prasannakumarkk
If there are no other columns, and the column header is static, hard code the static value in transfomer constraint column as not equal to

Posted: Tue Mar 12, 2013 3:29 am
by ShaneMuir
So the source is a DB? If that is the case - are you able to ensure that the first row selected is the header row? If you can you can just as easily exclude it in your select statement.

Split one column into multiple columns

Posted: Tue Mar 12, 2013 5:07 am
by surajspatil
even if i ensure the first row will always be headers, then how do i query to select all rows except first row, is there any db2 sql to do so?? i didn't find any in forums. plz provide me one sql where i can exclude first row.

Posted: Tue Mar 12, 2013 5:16 am
by prasannakumarkk
MTCN will never be char

Write you query as
select col1 from table where not col1 like 'MTCN%'

Re: Split one column into multiple columns

Posted: Tue Mar 12, 2013 6:30 am
by ShaneMuir
Use a nested select statement where you add a row number:

select * from
(select key, row_number() over(partition by 1) as rownum from table1)
where rownum > 1;