Page 1 of 1

Logic to split a column 100 characters long into 4 chunks...

Posted: Tue Aug 21, 2007 11:08 am
by Minhajuddin
Hi,

I am stuck with a tricky scenario. I have to split a column 'customer_name' which is 100 characters long into 4 chunks. The tricky part is that I am supposed to split it at spaces and also, then max number of characters in a chunk shouldn't be greater than 35. Is there a way we can do this in Datastage.

Any help is aprreciated.

Thank you.

Posted: Tue Aug 21, 2007 11:50 am
by kcbland
Transformer stage, use stage variables to help parse the text.

Posted: Tue Aug 21, 2007 12:57 pm
by us1aslam1us
Look into the Index() function.....

Posted: Tue Aug 21, 2007 1:58 pm
by ray.wurlod
If volumes are not large consider using a BASIC Transformer stage with either a Fold() or a Fmt() function.

Posted: Tue Aug 21, 2007 10:32 pm
by Maveric
Since the name has to be split at spaces why not field() and then len() to find the length of the string. what should be done if the length is more than 35? Ignore the space and split it at 35th character?

Posted: Tue Aug 21, 2007 10:36 pm
by ArndW

Code: Select all

INDEX(In.Col[1,35],' ',DCOUNT(In.Col[1,35],' ')-1)
will give the position of the last space before position 35. Assign from position 1 to this number to the first output string, then repeat (in stage variables) for the following 3.

Re: Logic to split a column 100 characters long into 4 chunk

Posted: Tue Aug 21, 2007 10:43 pm
by gaurav_shukla
Minhajuddin wrote:Hi,

I am stuck with a tricky scenario. I have to split a column 'customer_name' which is 100 characters long into 4 chunks. The tricky part is that I am supposed to split it at spaces and also, then max number of characters in a chunk shouldn't be greater than 35. Is there a way we can do this in Datastage.

Any help is aprreciated.

Thank you.
We can achive such functianlity by using Transformer and Stage Variables.
In Stage Variable cut the column by using Left and Right Function like
Left(Column_Name, 25). Use such function in four stage variables and cut the column accordingly.

Hope this helps

Posted: Tue Aug 21, 2007 11:51 pm
by ArndW
guarav - the original post states that words cannot be split, which is what doing a straight substring extraction would do.

Posted: Wed Aug 22, 2007 12:59 am
by gaurav_shukla
ArndW wrote:guarav - the original post states that words cannot be split, which is what doing a straight substring extraction would do. ...
In that case your's solution is correct.
I understand it wrongly!