Monday, June 29, 2015

Escaping underscore or other special characters in SQL query WHERE clause

There are two ways to escape underscore in SQL Server: square brackets and specifying escape character
SELECT * FROM TABLE1 WHERE FIELD1 LIKE '%\_%' ESCAPE '\'
or
SELECT * FROM TABLE1 WHERE FIELD1 LIKE '%[_]%' 


No comments:

Post a Comment