--需求:去掉字符串 doc.be_time between '2009-1-1' and '2010-1-1' 中的单引号set quoted_identifier off select string=replace("doc.be_time between '2009-1-1' and '2010-1-1'","'","") /* string ---------------------------------------------- doc.be_time between 2009-1-1 and 2010-1-1 */
4楼,请注意是单个单引号。如果是2个单引号在SQL中就不会出现问题了。 就好像 select * from a where aname like '%@a%' 其中@a 如果就是单个' 你能怎么办了。
set quoted_identifier off select charindex("'","doc.be_time between '2009-1-1' and '2010-1-1'")--21use test go if object_id('test.dbo.tb') is not null drop table tb go create table tb(col varchar(100)) go insert into tb select "天上''人间" union all select "数据'库" union all select "中国软件社区中心" goselect * from tb where col like "%'%"/* 查询结果 col ------------- 天上''人间 数据'库 */
--需求:去掉字符串 doc.be_time between '2009-1-1' and '2010-1-1' 中的单引号set quoted_identifier off
select string=replace("doc.be_time between '2009-1-1' and '2010-1-1'","'","")
/*
string
----------------------------------------------
doc.be_time between 2009-1-1 and 2010-1-1
*/
就好像 select * from a where aname like '%@a%'
其中@a 如果就是单个' 你能怎么办了。
http://www.baidu.com/s?bs=%B3%A2%27%CA%D4&f=8&wd=%2C
select charindex("'","doc.be_time between '2009-1-1' and '2010-1-1'")--21use test
go
if object_id('test.dbo.tb') is not null drop table tb
go
create table tb(col varchar(100))
go
insert into tb select "天上''人间"
union all select "数据'库"
union all select "中国软件社区中心"
goselect * from tb where col like "%'%"/* 查询结果
col
-------------
天上''人间
数据'库
*/