Using escape characters with MS SQL Server
SQLThis morning I was asked to do a quick and dirty query to find all rows from a table in MS SQL Server where a particular column contained one or more pecent sign (%) charaters. Considering the '%' character is a wildcard, I obviously needed an escape sequence, but oddly I had never run across this particular problem before. After a quick search I found what appears to be a Microsoft-specific solution that suited my needs. You can use an escape character in your 'where' clause, then define that character at the end of your query by adding {escape '[your character]'} like this:
SELECT
MyColumn
FROM
MyTable
WHERE
MyColumn like '%\%%'
{escape '\'}
I would like to underscore that the backslash character in my statement can be whatever you need it to be in case that is another point of conflict for you.





Loading....