Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need help with LIKE

Author  Topic 

bh0526
Yak Posting Veteran

71 Posts

Posted - 2010-07-01 : 17:08:59
I have a varchar column that I want to search on. But it's kinda strange what I am doing. First, let me give you 3 examples of what the data will look like in this column named "Result":

1. Negative for h1n1
2. h1n1; negative for salmonella
3. h1n1

I only want to select 2 and 3 above. I do not want to include #1 because "negative" comes before "h1n1". The problem is, it's not always this simple. There may be other words between the words "neagtive" and "h1n1".

So here are the rules for my selection:

1. Return all rows where "h1n1" is found but no occurences of "negative" is found

2. Return rows where Result contains "h1n1" but does not contain "negative" before the word "h1n1". It's ok for the word "negative" to be after "h1n1" though.

I know how to use the LIKE for #1. But I am not sure how to do this for #2.

Can anyone help?

Bob



Ret

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2010-07-01 : 17:35:02
NOT LIKE 'negative%h1n1%'

please cover your mouth when coughing

<><><><><><><><><><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page
   

- Advertisement -