I have a query that looks a bit like this:
SELECT * FROM Stuff WHERE name LIKE '[a\]]%'
My goal is to match all names starting with a
or ]
(closed bracket). However, this seems to match everything starting with a]
or \\]
.
Is this possible without OR
, a lot of auto-generated LIKE
s?
Best Answer
You have to escape the ]. That means before any character you want to literally search for, example
%
or_
or]
, you have to add anescape
character. For example\%
to search for a literal%
Example:
To read more about escape chars in LIKE, you can check :
LIKE Predicate Escape Character
You can also test it using SQL fiddle: SQL Fiddle