SQL Server LIKE 包含括号字符 [英] SQL Server LIKE containing bracket characters
问题描述
使用 SQL Server 2008.我有一个包含以下列的表:
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.
感谢您的任何建议!
推荐答案
... like '[[]%'
您使用 [ ]
来包围特殊字符(或范围)
You use [ ]
to surround a special character (or range)
请参阅 SQL Server LIKE中的使用通配符作为文字"部分一个>
编辑,2011 年 11 月 24 日
Edit, 24 Nov 2011
注意:您不需要转义结束括号...
Note: You don't need to escape the closing bracket...
这篇关于SQL Server LIKE 包含括号字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!