现在的位置: 首页 > 综合 > 正文

sql 中双引号的问题

2012年09月23日 ⁄ 综合 ⁄ 共 459字 ⁄ 字号 评论关闭

在sql 中 ' 单引号是用来表示字符串的,如果字符串中想包含 ' 单引号就需要转义,所以会看到 '''' 来表示一个 ' 字符串。这样在Sql语句中,除数字外都用上单引号,如果涉及到连接就用'+"..."+'

例如:

declare @strCondition  nvarchar(3000)

set @strCondition = @strCondition + ' and (userQuestion.topic like ''%'+ @key + '%'' or userQuestion.content like ''%'+ @key + '%'')' 

 

 declare @dd nvarchar(30)

declare @con nvarchar(3000)

declare @clubID int

set @con='UserID in'+'(select * from #temp)'+' and a.ClubID='+str(@clubID)+ 'and    a.rolename=@dd 

 

EXEC('DELETE [dbo].[aaa] WHERE MessageID IN ('+@IDs+')')

抱歉!评论已关闭.