SQL Server LIKE 包含括号字符 [英] SQL Server LIKE containing bracket characters

查看:90
本文介绍了SQL Server LIKE 包含括号字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆