LIKE operator in IF ELSE Condition

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
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

You can use

if index("DELL", InputString)=1 then "DELL" else (if index("Cisco", InputString)=1 then "Cisco" else 'N/A')

or you can use left/substring("[]") function to achive the same.
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 »

The Index() suggestion is akin to '%DELL%' rather than 'DELL%'. Use a simple substring check on the front of the string for that:

Code: Select all

If Link.Field[1,4] = 'DELL' then 'DELL' else if Link.Field[1,5] = 'Cisco' then 'Cisco' else 'N/A'
-craig

"You can never have too many knives" -- Logan Nine Fingers
sarathi
Participant
Posts: 27
Joined: Thu Feb 11, 2010 4:14 pm
Location: Minneapolis

Post by sarathi »

Thanks for comments. My task is NOT to check exact string but should work as Oracle like command - Like 'DELL%.

Tried to use Index send by Kunnal but not parsing.
Craig If Link.Field[1,4] condition is working but what if we have values 'DELL12' or 'Cisco32'

if index("DELL", LkFrom_CMDB_Table_Reject.VENDOR )=1 then "DELL" else (if index("Cisco", LkFrom_CMDB_Table_Reject.VENDOR)=1 then "Cisco" else 'N/A')

Sarathi
DSguru2B
Charter Member
Charter Member
Posts: 6854
Joined: Wed Feb 09, 2005 3:44 pm
Location: Houston, TX

Post by DSguru2B »

What Craig advised will work as 'DELL%'
Creativity is allowing yourself to make mistakes. Art is knowing which ones to keep.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That's the whole reason why Craig suggested it. :?

Checking Field[1,4] which disregards anything else that follows in the string is exactly the same functionality as checking for like 'XXXX%'.
-craig

"You can never have too many knives" -- Logan Nine Fingers
gateleys
Premium Member
Premium Member
Posts: 992
Joined: Mon Aug 08, 2005 5:08 pm
Location: USA

Post by gateleys »

So, MATCHES 'DELL...' did not work?
gateleys
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

That should be fine as well, I would imagine, depending on where it was being used.
-craig

"You can never have too many knives" -- Logan Nine Fingers
sarathi
Participant
Posts: 27
Joined: Thu Feb 11, 2010 4:14 pm
Location: Minneapolis

Post by sarathi »

If Link.Field[1,4] = 'DELL' then 'DELL' else is working.

I tried Matches 'DELL' with 'If then else' condition and it was not working.
My assumption is we need to use substring[] for IF THEN ELSE

Thanks for all :)

Sarathi
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

For processing efficiency load the first four characters into a stage variable, for example svFirstFour. Map to upper case if your data contain mixed case.

Code: Select all

If svFirstFour = "DELL" Then "DELL" Else If svFirstFour = "CISC" Then "Cisco" Else "N/A"
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Or use filter stage

.....and yes...it is not transformer state.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post by priyadarshikunal »

chulett wrote:The Index() suggestion is akin to '%DELL%' rather than 'DELL%'.
If the condition is index()=1 then it will work like 'DELL%' and index()<>0 is similar to '%DELL%'. :wink:

also the index command should be

if index(InputString, "DELL",1)=1 then "DELL" else (if index(InputString,"Cisco", 1)=1 then "Cisco" else 'N/A')
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 »

priyadarshikunal wrote:
chulett wrote:The Index() suggestion is akin to '%DELL%' rather than 'DELL%'.
If the condition is index()=1 then it will work like 'DELL%' and index()<>0 is similar to '%DELL%'. :wink:
True, but my point was that it does a substring match across the entire string so can find it anywhere and without you specifically checking where it found the string it can get you in trouble. To me it makes much more sense to just look at the first four (or five) characters if that's all you want to check, whether that's via substring or left. More efficient and more 'self documenting'. Yours can look like a simple true/false/zero/one test to the untrained or hurried eye. :wink:
-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 »

More efficient and more 'self documenting'. Yours can look like a simple true/false/zero/one test to the untrained or hurried eye. :wink:
I agree.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
Post Reply