To get data before commas and pipe

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
Cherukuri
Participant
Posts: 46
Joined: Wed Jul 25, 2007 2:43 am
Location: India
Contact:

To get data before commas and pipe

Post by Cherukuri »

Hi,

I have a quesion as below:

IPfield
Nafta,no2,2012|Cafta,no2,2012|bafta,no2,2012

should get a data like this below

OPfield
Nafta|Cafta|bafta

Please note the IPfield data can more with pipes.
for example i can also have data like:
Nafta,no2,2012|Cafta,no2,2012|bafta,no2,2012|Cafta,no2,2012|bafta,no2,2012

OPfield should be
Nafta|Cafta|bafta|Cafta|bafta

Could please help to figure out this logic.

Regards
Cheru
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Two Field() functions could pull each piece out, first delimited by pipe and then the result delimited by comma. If you are on 8.5 or higher, transformer looping can be used to iterate through the fields based on a count of the pipes.
-craig

"You can never have too many knives" -- Logan Nine Fingers
bhasds
Participant
Posts: 79
Joined: Thu May 27, 2010 1:49 am

Post by bhasds »

Hi Cherukuri,

If you have the pattern no2,2012 is common for each delimited substring then you can use-

Code: Select all

Convert("no2,2012","",IPfield )
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

With a BASIC Transformer stage you can use multi-value-handling functions such as Fields().

Code: Select all

Convert(@FM, ",", Fields(Convert("|", @FM, InLink.TheString), ",", 1, 1))
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

bhasds wrote:Hi Cherukuri,

If you have the pattern no2,2012 is common for each delimited substring then you can use-

Code: Select all

Convert("no2,2012","",IPfield )
That won't work for "nafta" because every "n" is converted to "".
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

What version of DS are your running. 8.5? If so you can solve this with the loop functionality in the transform.
Post Reply