码迷,mamicode.com
首页 > 数据库 > 详细

SQL多行合并成一行

时间:2014-12-31 17:58:46      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:

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

SQL多行合并成一行

标签:

原文地址:http://www.cnblogs.com/smilekiss/p/4195936.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!