Return values if they have a space ' ' ELSE don't return it

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
Tampa_Indy
Participant
Posts: 23
Joined: Tue Aug 04, 2015 12:45 pm

Return values if they have a space ' ' ELSE don't return it

Post by Tampa_Indy »

Can anyone provide guidance on creating an equation that will return values if a space exists in the field?

e.g. if you have the following values:

100 hits
strikeout
right field
shortstop

The returned values would be '100 hits' and 'right field'
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The Index() function. A non-zero return value = success in this case.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Tampa_Indy
Participant
Posts: 23
Joined: Tue Aug 04, 2015 12:45 pm

Post by Tampa_Indy »

Can you write an example for this? I was unable to get it to work.
Tampa_Indy
Participant
Posts: 23
Joined: Tue Aug 04, 2015 12:45 pm

Post by Tampa_Indy »

Will the field function work? I have the following:

if isnull(Field(lnk_Cast.BASEBALL," ",1)) THEN " " ELSE lnk_Cast.BASEBALL

So if the field does not contain a space, then it will return nothing otherwise it will return the field with the space. Correct?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

No, that's not what the Field() function does, best to recheck the docs for it. Why not shows us the Index() syntax you used? That should be the most straight-forward test to make.
-craig

"You can never have too many knives" -- Logan Nine Fingers
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Scroll down to the Index function in the URL below for the syntax. You'll need to copy/paste the whole thing as it is not clickable here, unfortunately.

Something like this perhaps, adjust as you see fit:

Code: Select all

If Index(lnk_Cast.BASEBALL," ",1) = 0 then <space not found logic> else <space found logic>
http://www-01.ibm.com/support/knowledge ... tions.html
-craig

"You can never have too many knives" -- Logan Nine Fingers
Tampa_Indy
Participant
Posts: 23
Joined: Tue Aug 04, 2015 12:45 pm

Post by Tampa_Indy »

I will give it a shot. Thank you!
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

This really only needs to be an output link constraint expression in a Transformer stage. There is no need for If..Then..Else.

Code: Select all

Index(lnk_Cast.BASEBALL, " ", 1) > 0
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Of course but the other syntax is usually easier for beginners to understand. Besides, who said anything about a output link constraint expression? :wink:

Tweak like so to treat the result as a Boolean:

Code: Select all

If Index(lnk_Cast.BASEBALL," ",1) then <space found logic> else <space not found logic>
Last edited by chulett on Thu Aug 27, 2015 7:26 am, edited 1 time in total.
-craig

"You can never have too many knives" -- Logan Nine Fingers
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

with a little correction

Code: Select all

If Index(lnk_Cast.BASEBALL," ",1) then <space found logic> else <space not found logic>

one should be "space not found logic" as it is an if-else block :wink:
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Of course, thanks. Got a little distracted editing the code. :wink:
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply