问题[与SQL语句 [英] Problem Of [ with Sql Statement

查看:80
本文介绍了问题[与SQL语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iam搜索项目表&我使用类似声明
例子

iam searching item table & i use like statment
example

declare @x nvarchar(1000)
select @x='ddd'

select * from item where lower(itemname) like lower(@x)+'%'

可以正常工作
但是如果项目名称包含[,则它不会出现在搜索中
当我写这封信时,这是声明,没有结果

it work fien no problem
but if the item name contain [ it doesn''t appear in the search
eban when i wrote this is statement no result

select * from item where itemname like '%[%'


所以任何机构都可以帮我吗


so can any body help me

推荐答案

这是因为LIKE是一个简单的Regex处理器,而"[''引入了一个字符序列:
...就像"x [abc] x"会匹配"xax","xbx"或"xcx"中的任何一个,但不会匹配"xdx"

参见此处: http://www.w3schools.com/sql/sql_wildcards.asp [
It''s because LIKE is a simple Regex processor, and ''['' introduces a sequence of characters:
...LIKE ''x[abc]x'' would match any of ''xax'', ''xbx'' or ''xcx'' but would not match ''xdx''

See here: http://www.w3schools.com/sql/sql_wildcards.asp[^]

I don''t know how you get round it though...

[edit]
Oh yes I do:
SELECT * FROM item WHERE itemname LIKE '%[[]%'


[/edit]


[/edit]


这篇关于问题[与SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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