Searching for a word in string in a column

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
Raamc
Premium Member
Premium Member
Posts: 87
Joined: Mon Aug 20, 2007 9:08 am

Searching for a word in string in a column

Post by Raamc »

Hi,

I have a column with data COL1='APPLE BANANA CHERRY ETC'. I want to check weather the word BANANA is there in the COL1 or not?

word BANANA may come at any position in COL1. Currently it is 2nd word but in real data it may come as 5th word also, even in that case also i need to return a flag.

Can any one help? I need to do this in Server jobs.
Thanks,
Raamc
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Code: Select all

INDEX(In.COL1,"BANANA",1)
will return 0 if the string is not found, or a numeric start position.
robjones
Participant
Posts: 24
Joined: Tue Nov 18, 2008 3:12 pm
Location: London

Re: Searching for a word in string in a column

Post by robjones »

Index(COL1,'BANANA',1) will return the position of the first occurrence of the text 'BANANA' in your column, or 0 if the text can't be found.
robjones
Participant
Posts: 24
Joined: Tue Nov 18, 2008 3:12 pm
Location: London

Post by robjones »

ArndW wrote:

Code: Select all

INDEX(In.COL1,"BANANA",1)
will return 0 if the string is not found, or a numeric start position. ...

Too quick for me!
Raamc
Premium Member
Premium Member
Posts: 87
Joined: Mon Aug 20, 2007 9:08 am

Post by Raamc »

Hi All,

The word BANANA may come also as BANANALYKJKJS or BANANALY etc in COL1.
The below given code will return TRUE even for this kind of strings also?
Thanks,
Raamc
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post by ArndW »

Yes, so look for "BANANA " and/or " BANANA" to avoid that type of error.

p.s. Rob - I'm here because my compiles are taking 30 minutes or longer today :)
Raamc
Premium Member
Premium Member
Posts: 87
Joined: Mon Aug 20, 2007 9:08 am

Post by Raamc »

Thanks ArndW.

I will test this. Meanwhile i have given one try on function COUNT in basic. It is also working it seems.

I put this function in a routine and tested. Code is as below

Ans = COUNT (Arg1,Arg2)

Arg1 is my COL1
Arg2 is my string to search.

It is returning the valid count.

Thanks again,
Thanks,
Raamc
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Better search with delimiters.

Code: Select all

sourceString = '|' : Convert(' ', '|', yourString) : '|'
searchString = '|' : yourSearchString : '|'
stringPresent = Index(sourceString, searchString, 1)
This will avoid BANANAMILKSHAKE to agree for BANANA.
Post Reply