SELECT变量多值赋值 举例说下
SELECT变量多值赋值 举例说下
比如表 test 字段 sname,要把查询的sname的值负给变量@str
[解决办法]
create table #test(name varchar(10))goinsert #testselect 'tracy' union allselect 'lucy' union allselect 'kobe'godeclare @str varchar(50)set @str=''select @str=@str+','+name from #testselect RIGHT(@str,LEN(@str)-1) as name/*nametracy,lucy,kobe*/