Match by range or set

suggest change

In SQL Server, a character class matches one character in a range (for example [a-f]) or a set (for example [abcdef]). This is not standard LIKE. Standard patterns have only % and _.

This range pattern would match “gary” but not “mary”:

SELECT * FROM Employees WHERE FName LIKE '[a-g]ary'

This set pattern would match “mary” but not “gary”:

SELECT * FROM Employees WHERE Fname LIKE '[lmnop]ary'

The range or set can also be negated by appending the ^ caret before the range or set:

This range pattern would not match “gary” but will match “mary”:

SELECT * FROM Employees WHERE FName LIKE '[^a-g]ary'

This set pattern would not match “mary” but will match “gary”:

SELECT * FROM Employees WHERE Fname LIKE '[^lmnop]ary'

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents