How to escape a string for use with the LIKE operator in SQL Server?

后端 未结 7 1406
半阙折子戏
半阙折子戏 2020-12-15 07:59

I am looking for something that works in SQL Server similar to the @ symbol in c# which causes a string to be taken as it\'s literal. Eg:

strin         


        
7条回答
  •  暖寄归人
    2020-12-15 08:34

    In TSQL, you can wrap the % and _ characters in brackets like so [%] [_] this tells SQL to treat them as literals.

    I have tested and verified this works in SQL Server 7.0, 2000, and 2005.

    http://msdn.microsoft.com/en-us/library/aa933232(SQL.80).aspx

提交回复
热议问题