Substring/parse question

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
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Substring/parse question

Post by Marley777 »

Hi, thanks for reading. Any help is greatly appreciated.

I need help with parsing data in an input field.

If I have the following in my varchar 255 input filed
part1-part2-part3-part4-part5

I want to put part1 and part2 in one field and all other parts in another field. The dash between part2 and part3 is not needed because it's a delimiter, but I need to keep the dash between all other parts because it's part of the data. Any ideas on how to do this?

Below is what I'm trying to do

Newfield 1
part1-part2

Newfield 2
part3-part4-part5
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Use Field() and tell it the field is "-" delimited. For the first part, take 2 fields starting from field 1, for the second take 3 fields starting with field 3. The optional argument after the field number to extract controls how many fields to extract. It defaults to 1 if you don't specify it.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Code: Select all

NewField1 <--  Field(OldField, "-", 1, 2)
NewField2 <--  Field(OldField, "-", 3, 3)
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Marley777
Premium Member
Premium Member
Posts: 316
Joined: Tue Jan 27, 2004 3:26 pm

Post by Marley777 »

Thanks this worked for us.
Post Reply