执行
SELECT userid FROM userinfo
得到
1
2
3
4
如果要得到
1,2,3,4
执行方案1
DECLARE @STR VARCHAR(8000)
SELECT @STR=ISNULL(@STR+',','')+userid FROM (SELECT DISTINCT userid FROM userinfo)AS T
SELECT @STR
执行方案2
declare @output varchar(8000)
select @output = coalesce(@output + ',' , '') + userid from userinfo
print @output