Use Wildcard Characters as Literal Characters

You can search for wildcard characters by using the escape character and searching for them as literals. There are two ways to use the wildcard characters as literals in a like match string: square brackets and the escape clause.

The match string can also be a variable or a value in a table that contains a wildcard character.

Square Brackets (Transact-SQL Extension)

Use square brackets for the percent sign, the underscore, and right and left brackets. To search for a dash, rather than using it to specify a range, use the dash as the first character inside a set of brackets.

like Clause

Searches for

like "5%"

5 followed by any string of 0 or more characters

like "5[%]"


like "_n"

an, in, on, and so forth

like "[_]n"


like "[a-cdf]"

a, b, c, d, or f

like "[-acdf]"

-, a, c, d, or f

like "[ [ ]"


like "[ ] ]"


escape Clause (SQL-Compliant)

Use the escape clause to specify an escape character in the like clause. An escape character must be a single-character string. Any character in the server’s default character set can be used.

like clause

Searches for

like "5@%" escape "@"


like "*_n" escape "*"


like "%80@%%" escape "@"

String containing 80%

like "*_sql**%" escape "*"

String containing _sql*

like "%#####_#%%" escape "#"

String containing ##_%