SQL语句中单引号
SQL语句中单引号一、写SQL语句时,条件中会有两个单引号,但是本身又被单引号包括
例如:
select * from control where column=' ' 如果column中的条件为 ddd 'g'
解决方法为
在column的条件中用两个单引号来表示一个单引号,例如
select * from control where column=' ddd ''g'''
二、存储过程中使用单引号的实例
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 tableddd As p ,tableeee As m ,tablefff c WHERE p.EmpID = m.EmpID and p.CateID = c.CateID and '
+ @SearchString