Check if row contains another row

In T-SQL, how would you check if a row contains no rows?

I have nvarchar , which may be "Oranges Eggs."

I would like to do an update where, for example, columm does not contain "Apples."

How can I do that?

+50
string sql-server tsql
Aug 07 '09 at 18:42
source share
4 answers
 WHERE NOT (someColumn LIKE '%Apples%') 
+74
Aug 07 '09 at 18:44
source share

Or, alternatively, you can use this:

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

Not sure which one works best - you should check it out !:-)

Mark

UPDATE: performance seems to be pretty much in line with another solution (WHERE someColumn NOT LIKE '% Apples%') - so it's really just a matter of your personal preference.

+23
Aug 07 '09 at 18:46
source share

Use this as a WHERE clause.

 WHERE CHARINDEX('Apples', column) = 0 
+10
Aug 7 '09 at 18:46
source share

Responses to which you suggested static text for comparison. If you want to compare with another column (for example, you join two tables and want to find those where a column from one table is part of a column from another table), you can do this

 WHERE NOT (someColumn LIKE '%' || someOtherColumn || '%') 
+7
Aug 29 '12 at 21:33
source share



All Articles