How to escape underscore character in PATINDEX pattern argument?

后端 未结 3 937
南笙
南笙 2020-12-24 01:54

I\'ve found a solution for finding the position of an underscore with PATINDEX :

DECLARE @a VARCHAR(10)  
SET     @a = \'37_21\'

PRINT PATINDEX(\'%_%\', @a)         


        
3条回答
  •  半阙折子戏
    2020-12-24 02:11

    To match two underscores, each must be bracketed

    '%[__]%' -- matches single _ with anything after
    
    '%[_][_]%' -- matches two consecutive _
    

提交回复
热议问题