+ -
当前位置:首页 → 问答吧 → SQL Server2005中模糊匹配问题?

SQL Server2005中模糊匹配问题?

时间:2011-12-16

来源:互联网

我在SQL2005中使用模糊匹配 a like '%'+@var+'%'

表中a 字段含有“+”符号,在匹配时,含有+为什么不能查询出来?

作者: fcltuteng   发布时间: 2011-12-16

SQL code

--不会吧,是不是数据有问题,我的可以查like出来
if object_id('tb') is not null
   drop table tb
go
create table tb
(
 id int identity(1,1),
 name varchar(20)
)
go
insert into tb(name)
select '123abc456' union all
select 'abcd+efg'
go
select * from tb where name like '%d+e%'
go
/*
id          name
----------- --------------------
2           abcd+efg

(1 行受影响)

*/

作者: pengxuan   发布时间: 2011-12-16

应该是没有问题的吧

作者: fredrickhu   发布时间: 2011-12-16

这样应该可以,关键是我是通过字符串的连接,('%'+@var+'%')问题应该是出在这里面的+号吧!

作者: fcltuteng   发布时间: 2011-12-16

引用 2 楼 fredrickhu 的回复:

应该是没有问题的吧

会不会是出在字符串连接中的“+”号

作者: fcltuteng   发布时间: 2011-12-16

www.xiangshui88.com

www.flm8.com

作者: wokinuni110   发布时间: 2011-12-16