0

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?

Who Dis
  • 78
  • 8

1 Answers1

4

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) = ']'
Stu
  • 30,392
  • 6
  • 14
  • 33
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786