How can I tell if a VARCHAR variable contains a substring?

后端 未结 4 679
我在风中等你
我在风中等你 2021-01-30 20:07

I thought it was CONTAINS, but that\'s not working for me.

I\'m looking to do this:

IF CONTAINS(@stringVar, \'thisstring\')
   ...
<         


        
4条回答
  •  一个人的身影
    2021-01-30 20:38

    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'
    

提交回复
热议问题