Check if a string contains a substring in SQL Server 2005, using a stored procedure

前端 未结 2 1102
离开以前
离开以前 2020-11-30 00:50

I\'ve a string, @mainString = \'CATCH ME IF YOU CAN\'. I want to check whether the word ME is inside @mainString.

How do I che

2条回答
  •  一生所求
    2020-11-30 01:24

    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).

提交回复
热议问题