Link to home
Start Free TrialLog in
Avatar of Mark Bakelaar
Mark BakelaarFlag for Norway

asked on

sql like excluding

Hi Experts.
I use the following like statement lower(tekst) like '%est%' that gives me also some results I would like to exclude:
- EST D/A Alexandria V 22
- D/A Brest v 86 oppgj

How can I best approach this?

Best regards,
MB
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

Try using binary collation.  Try the following:

WHERE tekst like '%est%' COLLATE Latin1_General_BIN


I hope it helps.
Hi,

By the way, if you are really just after excluding the two results, then "matthewspatrick" answer is sufficient.
Avatar of Mark Bakelaar

ASKER

Hi Alfred1, I was just writing the following comment.

Hi matthewspatrick,

The example given might have been somewhat to simple in a way that I would like to exclude everything that has the word "Brest" in it, I would like to only get the abbreviation EST.
Hi,

Can I just confirm, you are just after EST or est?

You could do it this way if est only and not EST:

WHERE tekst like '% est %' COLLATE Latin1_General_BIN

or,

You could do it this way if EST only

WHERE tekst like '% EST %' COLLATE Latin1_General_BIN
Avatar of Tyug
Tyug

Use another like statement for your examples. If there are any other commonalities, try to include those as well to not get unexpected results.

small modification to matthewspatrick's ...

WHERE lower(tekst) like '%est%' AND tekst NOT LIKE '%EST%' AND tekst NOT LIKE '%Brest%'
Hi,

Aha.  Ok.  you want Br of Brest out of the picture.  You could do it this way.

WHERE tekst like '% EST %' COLLATE Latin1_General_BIN
AND tekst not like 'Br%' COLLATE Latin1_General_BIN

Sorry for the late reply, thanks for the help.