sqlserver中转义的写法问题

fxsy6669 2010-04-07 04:26:12
select * from export where 品牌 is not null and 文章标题 like '%还要忍多久?丰田的'刹车'与'回归'%'
这句查询语句转义怎么写呀,请大家帮下忙,谢了
...全文
265 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuifengde 2010-04-07
  • 打赏
  • 举报
回复
select * from export where 品牌 is not null and 文章标题 like "%还要忍多久?丰田的'刹车'与'回归'%"
feixianxxx 2010-04-07
  • 打赏
  • 举报
回复
create table #(code varchar(20),value int)
declare @sql varchar(200)


set @sql='insert into # select ''AAA'',10'
-- AAA之前的一对单引号与之后的一对单引号分别代表一个单引号

print @sql --查看这个字符串的实际内容
/*
insert into # select 'AAA',10
*/

exec(@sql)
select * from #
/*
code value
-------------------- -----------
AAA 10
*/

--如果需要insert一个值为'A''AA'的字符串,如下:
set @sql='insert into # select ''A''''AA'',10'
--两层嵌套的字符串内部,一个单引号需要经过两次转义,于是变成了4个单引号

print @sql --查看这个字符串的实际内容
/*
insert into # select 'A''AA',10
*/

exec(@sql)

select * from #
/*
code value
-------------------- -----------
AAA 10
A'AA 10
*/


drop table #
htl258_Tony 2010-04-07
  • 打赏
  • 举报
回复
在字符串中,两个'等于常规下的一个'
htl258_Tony 2010-04-07
  • 打赏
  • 举报
回复
select * from export where 品牌 is not null and 文章标题 like '%还要忍多久?丰田的''刹车''与''回归''%'
SQL77 2010-04-07
  • 打赏
  • 举报
回复
select * from export where 品牌 is not null
and 文章标题 like '%还要忍多久?丰田的''刹车''与''回归''%'

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧