I've a string, @mainString = 'CATCH ME IF YOU CAN'
. I want to check whether the word ME
is inside @mainString
.
How do I check if a string has a specific substring in SQL?
This question is related to
sql-server
string
tsql
stored-procedures
sql-server-2005
You can just use wildcards in the predicate (after IF, WHERE or ON):
@mainstring LIKE '%' + @substring + '%'
or in this specific case
' ' + @mainstring + ' ' LIKE '% ME[., ]%'
(Put the spaces in the quoted string if you're looking for the whole word, or leave them out if ME can be part of a bigger word).
Source: Stackoverflow.com