Parsing a Varchar Field

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
als110
Participant
Posts: 43
Joined: Fri Nov 05, 2004 11:21 am
Location: United States

Parsing a Varchar Field

Post by als110 »

I have a field in the following format:

50% (ABC: $1,000)
100% (ABC: $5,000)

I want to parse this into 2 columns so that the result looks as follows

A B
50% $1,000
100% $5,000

Is there a function in data stage or a combination of functions where I can look for a % or a $ and then take everything to the left of the percentage sign or everything to the right of the $ sign.

Thanks

Aaron
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

INDEX(MyString,'$',1) returns the position of the first $ in the string.

But in your case I might use:

PercentageValue = FIELD(In.StringVar,'%',1)
DollarValue = FIELD(In.StringVar,'$',2)

This treats the % and $ signs as if they were field separators and, to use the example of '%', it parses the string into 2 fields "50" and " ABC: $1000)". This is an easy way to parse strings, but using the INDEX() function and specific substring lengths is more efficient at runtime.
Post Reply