SQLServer: how to search for %, _, [, sqlserver
There are two methods:
1. Use ESCAPE to define ESCAPE characters
"%" And""And" [] "are considered as wildcards when they appear separately. In order to check whether there are percent signs (%), underlines () Or square brackets ([]), you need to use a method to tell DBMS to regard these characters in the LIKE criterion as actual values rather than wildcards. The keyword ESCAPE allows you to determine an ESCAPE character, telling DBMS that the character following the ESCAPE character is considered as the actual value.
For example:
-- Query records starting with %. Note: M is an escape character. SELECT * FROM tableName a WHERE a. field LIKE 'M %' ESCAPE 'M'
2. Use [] to enclose escape characters.
For example:
-- Query records starting with %. SELECT * FROM tableName a WHERE a. field LIKE '[%] %'
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.