ironcurtain
ironcurtain

Reputation: 690

How do I use select with multiple like conditions in T-SQL?

I would like to select all records from a table which are not like '%select%' but except these which contains '%select some_string%' and '%select some_other_string%'.

How do I do this in T-SQL?

Upvotes: 0

Views: 1595

Answers (3)

Vipin Kumar
Vipin Kumar

Reputation: 17

You can try the following it may help

SELECT *
FROM TABLE
WHERE Coloumn NOT LIKE 'select'
    AND Coloumn LIKE '%select some_string%'

Upvotes: 0

fancyPants
fancyPants

Reputation: 51888

With my english skills I get another solution than dasblinkenlight's:

WHERE (NOT (s LIKE '%select%'))
  OR s LIKE '%select some_string%' OR s LIKE '%select some_other_string%'

Upvotes: 1

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726639

A straightforward translation from English to SQL should work fine:

WHERE (NOT (s LIKE '%select%'))
  AND NOT ((s LIKE '%select some_string%') OR (s LIKE '%select some_other_string%'))

Upvotes: 1

Related Questions