SQL多行合并成一行

with cte as(
select groupname,GroupId from Sys_Group where GroupId in(
select ReleaseRangeId from Sys_Notice_Permission where ReleaseRangeType=2 and NoticeId=20)
)

select LEFT(groupname,LEN(groupname)-1) as groupname,
LEFT(GroupId,LEN(GroupId)-1) as GroupId

from
(
SELECT (SELECT groupname+',' from cte FOR XML PATH('') ) as groupname,
(SELECT cast(GroupId as nvarchar)+',' from cte FOR XML PATH('') ) as GroupId

) A

posted @ 2014-12-31 16:04  Adam_Li  阅读(664)  评论(0编辑  收藏  举报