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.
Searching for a word in string in a column
Moderators: chulett, rschirm, roy
Searching for a word in string in a column
Thanks,
Raamc
Raamc
Code: Select all
INDEX(In.COL1,"BANANA",1)
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
Re: Searching for a word in string in a column
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.
ArndW wrote:will return 0 if the string is not found, or a numeric start position. ...Code: Select all
INDEX(In.COL1,"BANANA",1)
Too quick for me!
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
p.s. Rob - I'm here because my compiles are taking 30 minutes or longer today
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
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,
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
Raamc
-
- Participant
- Posts: 3337
- Joined: Mon Jan 17, 2005 4:49 am
- Location: United Kingdom
Better search with delimiters.
This will avoid BANANAMILKSHAKE to agree for BANANA.
Code: Select all
sourceString = '|' : Convert(' ', '|', yourString) : '|'
searchString = '|' : yourSearchString : '|'
stringPresent = Index(sourceString, searchString, 1)