概述
with cte as
(
select vcOrganID, vcParentID, vcOrganName, 0 as lvl from tbOrgan
where vcOrganID = 2
union all
select d.vcOrganID, d.vcParentID, d.vcOrganName, lvl+1
from cte c inner join tbOrgan d on c.vcOrganID = d.vcParentID
)
select * from cte
select
vcOrganID, vcParentID, vcOrganName,vcOrder,
STUFF((select ',' + vcOrganID from tbOrgan
where o.vcOrder like vcOrder+'%' and o.vcOrder<>vcOrder
order by vcOrder
FOR XML PATH('')), 1, 1, '') as parentIds
from tbOrgan o
order by vcOrder
转载于:https://www.cnblogs.com/shijun/p/4923158.html
最后
以上就是快乐路人为你收集整理的组织机构sql的全部内容,希望文章能够帮你解决组织机构sql所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复