declare @rowids nvarchar(100) set @rowids='' select @rowids=@rowids+''''+rowids+''''+',' from table set @rowids=left(@rowids,len(@rowids)-1) select @rowids
https://www.cnblogs.com/zhming26/p/6382995.html两个函数,看你要用那个了
select GROUP_CONCAT('\'',rowid,'\'') from tablename
MSSQL没有GROUP_CONCAT这个内建函数吧
http://www.cnblogs.com/tonightdream/p/8709123.html
针对你的问题写的,看解决问题了没
多谢老哥还专门写了篇文章,昨天我找到了一种更方便的写法,如下
declare @rowids nvarchar(100) set @rowids='' select @rowids=@rowids+''''+uid+''''+',' from table set @rowids=left(@rowids,len(@rowids)-1) select @rowids
@Mr.sw: 这个方法简单
DECLARE @str varchar(8000) SET @str = '' select @str=@str+ cast(name as varchar(10))+',' from (select 1 as name union select 2 union select 3 union select 4) tableA print @str
select rowid+',' from tableName for xml path('')
rowid是int类型需要转换一下
select ''''+convert(nvarchar,rowid)+''',' from tableName for xml path('')