存储过程 单引号

来源:百度知道 编辑:UC知道 时间:2024/06/08 16:08:58
set @ssql =
select top + cast(@__lastindex as nvarchar) +
@skeys = + @skeys + case when @index >= + cast(@__firstindex as nvarchar) +
then cast(userid as nvarchar) + ,
else end,
@index = @index + 1
from dbo.tbl_user
+ @__whereclause +
order by + @__sortfield + @__order

假设表的内容是:
userid username
aaa aaaname
bbb bbbname
这句sql语句出来的结果是 skeys = aaa,bbb,
我希望skeys =aaa,bbb, 应该在 cast(userid as nvarchar) 的前后加一个单引号,可是我试了好多方法都没有成功,请大家帮帮忙,谢谢

1) 可以用''''表示字符串中的一个单引号,
如:set @a = '''' + 'xxxx' + ''''
或者 set @account = '''xxxx'''

查询分析器中执行 Print ''''
结果为 '

2)用Char(39),上例变为:set @a = char(39) + 'xxxx' + char(39)

查询分析器中执行 Select char(39) + 'xxxx' + char(39)
结果为 'xxxx'

好乱啊!
怎么这么多变量啊?
你还是直接说出你这个存储过程要干什么吧。

cast(userid as nvarchar) + ,
你运行的结果最后肯定会有,,如果最后那个不想要!直接处理下得出的结果就好了!