How can I escape square brackets in a LIKE clause?
LIKE 'WC[[]R]S123456'
or
LIKE 'WC\[R]S123456' ESCAPE '\'
Should work.
Let's say you want to match the literal its[brac]et
.
You don't need to escape the ]
as it has special meaning only when it is paired with [
.
Therefore escaping [
suffices to solve the problem. You can escape [
by replacing it with [[]
.
I needed to exclude names that started with an underscore from a query, so I ended up with this:
WHERE b.[name] not like '\_%' escape '\' -- use \ as the escape character