Match by range or set
suggest changeIn 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'
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents