查询结果列传行

with cte as
(
select id,parent_id from [dbo].[manager_Department] where id=42
union all
select b.id,b.parent_id from cte a join [dbo].[manager_Department] b on b.parent_id=a.id
)
select top 1 stuff ( (select ( ','+convert(varchar(50), id)) from cte for xml path('') ) ,1,1,'') as col from cte

从带有层级的部门表中取出当前部门及下级部门的id,并转成行

posted @ 2016-05-26 19:59  Alfred.Xu  阅读(135)  评论(0编辑  收藏  举报