sql 中双引号的问题

在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+')')

posted @ 2010-03-29 17:38  anny0320  阅读(1371)  评论(0)    收藏  举报