views:

79

answers:

2

Using SQL Server 2008. I have a table with the following column:

sampleData (nvarchar(max))

The value for this column in some of these rows are lists formatted as follows:

["value1","value2","value3"]

I'm trying to write a simple query that will return all rows with lists formatted like this, by just detecting the opening bracket.

SELECT * from sampleTable where sampleData like '[%'

The above query doesn't work because '[' is a special character, and I can't for the life of me figure out how to escape the bracket so my query does what I want.

Thanks for any suggestions!

+8  A: 
 ... like '[[]%'

You use [ ] to surround a special character (or range)

See the section "Using Wildcard Characters As Literals" in SQL Server LIKE

gbn
Works like a charm - thanks!
CJS
+1  A: 

Aside from gbn's answer, the other method is to use the ESCAPE option:

SELECT * from sampleTable where sampleData like '\[%' ESCAPE '\'

See the documentation for details

Ed Harper