How can I select only values that start and end with square brackets?
I have written
LIKE '[%]'
but it does not return anything. How can I work around this?
How can I select only values that start and end with square brackets?
I have written
LIKE '[%]'
but it does not return anything. How can I work around this?
You need to escape the square brackets, because they are special characters in SQL Server LIKE
patterns (square braces delineate character classes):
where col like '\[%\]'
If you don't like backslashes, you can use:
where col like '$[%$]' escape '$'
or not use LIKE
at all:
where left(col, 1) = '[' and right(col, 1) = ']'