sql server中sql语句中单引号怎么转义
3个回答
推荐于2016-02-11
展开全部
当SET QUOTED_IDENTIFIER OFF时, "是字符串边界符, 字符串中的"必须用两个"表示。
vb: "" <=> "
sql server 2000: ''' <=> '
eg:
declare @SearchType nvarchar(50)
declare @SearchString nvarchar(255)
declare @SearchKey nvarchar(50)
declare @SearchSql nvarchar(2000)
set @SearchType = '2'
set @SearchKey = 'd'
set @SearchString = CASE @SearchType
when '1' then '1 = 1'
when '2' then 'p.ProjectName like ''' + '%' + @searchkey + '%' + ''''
when '3' then 'p.ProjectCity like ''' + '%'+ @searchkey + '%' +''''
when '4' then 'c.CateName like ''' + '%' + @searchkey + '%' + ''''
when '4' then 'p.ProjectManager like ''' + '%' + @searchkey + '%' +''''
END
set @SearchSql = N'
SELECT p.*,datename(year,ProjectPostTime)+ ' + '''-''' + ' + datename(month,ProjectPostTime)+ '+ '''-''' + ' + datename(day,ProjectPostTime)' + ' as PostTime, m.EmpName,c.CateName FROM proProject As p ,mrBaseInf As m ,proCate c WHERE p.EmpID = m.EmpID and p.CateID = c.CateID and '
+ @SearchString
print(@SearchSql)
exec(@SearchSql)
vb: "" <=> "
sql server 2000: ''' <=> '
eg:
declare @SearchType nvarchar(50)
declare @SearchString nvarchar(255)
declare @SearchKey nvarchar(50)
declare @SearchSql nvarchar(2000)
set @SearchType = '2'
set @SearchKey = 'd'
set @SearchString = CASE @SearchType
when '1' then '1 = 1'
when '2' then 'p.ProjectName like ''' + '%' + @searchkey + '%' + ''''
when '3' then 'p.ProjectCity like ''' + '%'+ @searchkey + '%' +''''
when '4' then 'c.CateName like ''' + '%' + @searchkey + '%' + ''''
when '4' then 'p.ProjectManager like ''' + '%' + @searchkey + '%' +''''
END
set @SearchSql = N'
SELECT p.*,datename(year,ProjectPostTime)+ ' + '''-''' + ' + datename(month,ProjectPostTime)+ '+ '''-''' + ' + datename(day,ProjectPostTime)' + ' as PostTime, m.EmpName,c.CateName FROM proProject As p ,mrBaseInf As m ,proCate c WHERE p.EmpID = m.EmpID and p.CateID = c.CateID and '
+ @SearchString
print(@SearchSql)
exec(@SearchSql)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在字符串内部用两个单引号表示一个
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2015-01-31
展开全部
不懂,你转译要用在什么地方?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询