declare @sql nvarchar(2000)
SET @sql = CASE @ShowType
WHEN 1 THEN 'select top '+cast(@TopNum as varchar)+' * from RLNotices where NoticeType=1'
WHEN 2 THEN 'select top '+cast(@TopNum as varchar)+' * from RLNotices where NoticeType=2 and CHARINDEX(','+LTRIM(@UserID)+',', ','+ShowType+',')>0'
WHEN 3 THEN 'select top '+cast(@TopNum as varchar)+' * from RLNotices where NoticeType=3 and ShowType='+LTRIM(@UserID)+''
ELSE '0' END
set @sql=@sql+' order by ID desc'
ExEc (@sql)
WHEN 1 THEN 'select top '+cast(@TopNum as varchar)+' * from RLNotices where NoticeType=1'
WHEN 2 THEN 'select top '+cast(@TopNum as varchar)+' * from RLNotices where NoticeType=2 and CHARINDEX('',''+LTRIM(@UserID)+'','', '',''+ShowType+'','')>0'
WHEN 3 THEN 'select top '+cast(@TopNum as varchar)+' * from RLNotices where NoticeType=3 and ShowType='+LTRIM(@UserID)+''
ELSE '0' END
SET @sql = CASE @ShowType
WHEN 1 THEN 'select top '+CAST(@TopNum AS VARCHAR)+
' * from RLNotices where NoticeType=1'
WHEN 2 THEN 'select top '+CAST(@TopNum AS VARCHAR)+
' * from RLNotices where NoticeType=2 and CHARINDEX('','+LTRIM(@UserID)+','', '',''
+ShowType+'','')>0'
WHEN 3 THEN 'select top '+CAST(@TopNum AS VARCHAR)+
' * from RLNotices where NoticeType=3 and ShowType='+LTRIM(@UserID)
ELSE '0'
END
SET @sql = @sql+' order by ID desc'
EXEC (@sql)
select 'aa''a'
会显示出
aa'a
又如
set @x='aa''a'
@x的内容其实就是aa'a