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
  • 54
  • 7

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
  • 19,456
  • 3
  • 10
  • 28
Gordon Linoff
  • 1,198,228
  • 53
  • 572
  • 709