Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string doesn't contain another string

In T-SQL, how would you check if a string doesn't contain another string?

I have an nvarchar which could be "Oranges Apples".

I would like to do an update where, for instance, a columm doesn't contain "Apples".

How can this be done?

like image 700
Dofs Avatar asked Aug 07 '09 18:08

Dofs


People also ask

How do you check if a string contains another string?

1. Using String#contains() method. The standard solution to check if a string is a substring of another string is using the String#contains() method. It returns true if the string contains the specified string, false otherwise.

How do I check if a string contains another string in Python?

To check if a string contains a substring in Python using the in operator, we simply invoke it on the superstring: fullstring = "StackAbuse" substring = "tack" if substring in fullstring: print("Found!") else: print("Not found!")

How do I check if a string not contains a specific word?

You can use the PHP strpos() function to check whether a string contains a specific word or not. The strpos() function returns the position of the first occurrence of a substring in a string. If the substring is not found it returns false . Also note that string positions start at 0, and not 1.

How do you check if a string contains another string in Javascript?

The includes() method returns true if a string contains a specified string. Otherwise it returns false .


2 Answers

WHERE NOT (someColumn LIKE '%Apples%') 
like image 52
Daniel A. White Avatar answered Oct 03 '22 16:10

Daniel A. White


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.

like image 35
marc_s Avatar answered Oct 03 '22 15:10

marc_s