How can I tell if a VARCHAR variable contains a substring?
The standard SQL way is to use like:
where @stringVar like '%thisstring%'
That is in a query statement. You can also do this in TSQL:
if @stringVar like '%thisstring%'
Instead of LIKE
(which does work as other commenters have suggested), you can alternatively use CHARINDEX
:
declare @full varchar(100) = 'abcdefg'declare @find varchar(100) = 'cde'if (charindex(@find, @full) > 0) print 'exists'
CONTAINS
is for a Full Text Indexed field - if not, then use LIKE