There are two ways of doing this:
I. Using escape to define an escape character
When a fuzzy query is made using the LIKE keyword, "%", "" "and" [] "are considered to be wildcard characters when they appear separately. In order to query for the presence of a percent sign (%), underscore (), or square bracket ([]) character in a column of a character data type, you need a way to tell the DBMS to treat these characters in a like-sentence as actual values rather than as wildcard characters. The keyword escape allows you to determine an escape character that tells the DBMS that the character immediately following the escape character is considered an actual value.
Such as:
--查询以 % 开头的记录。注:M 为转义字符。SELECT * FROM tableName a WHERE a.field LIKE ‘M%%‘ ESCAPE ‘M‘
Use [] to enclose the characters that need to be escaped.
Such as:
--查询以 % 开头的记录。SELECT * FROM tableName a WHERE a.field LIKE ‘[%]%‘
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SQL Server: How to search for%, _, [