Check if string doesn't contain another string Check if string doesn't contain another string sql-server sql-server

Check if string doesn't contain another string


WHERE NOT (someColumn LIKE '%Apples%')


Or alternatively, you could use this:

WHERE CHARINDEX(N'Apples', someColumn) = 0

Not sure which one performs better - you gotta test it! :-)

Marc

UPDATE: the performance seems to be pretty much on a par with the other solution (WHERE someColumn NOT LIKE '%Apples%') - so it's really just a question of your personal preference.


Use this as your WHERE condition

WHERE CHARINDEX('Apples', column) = 0