Page 1 of 1

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

Posted: Mon Aug 24, 2015 11:13 am
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'

Posted: Mon Aug 24, 2015 12:18 pm
by chulett
The Index() function. A non-zero return value = success in this case.

Posted: Mon Aug 24, 2015 12:26 pm
by Tampa_Indy
Can you write an example for this? I was unable to get it to work.

Posted: Mon Aug 24, 2015 12:53 pm
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?

Posted: Mon Aug 24, 2015 1:01 pm
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.

Posted: Mon Aug 24, 2015 1:09 pm
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

Posted: Wed Aug 26, 2015 2:26 pm
by Tampa_Indy
I will give it a shot. Thank you!

Posted: Wed Aug 26, 2015 6:15 pm
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

Posted: Wed Aug 26, 2015 8:59 pm
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>

Posted: Thu Aug 27, 2015 1:10 am
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:

Posted: Thu Aug 27, 2015 7:28 am
by chulett
Of course, thanks. Got a little distracted editing the code. :wink: