递归查询数据库

WITH tempDept
AS
(
SELECT deptCode,upDeptCode FROM dbo.bs_Dept WHERE deptCode='10.001'
UNION ALL
SELECT bs_Dept.deptCode,bs_Dept.upDeptCode FROM tempDept
INNER JOIN dbo.bs_Dept ON dbo.bs_Dept.upDeptCode=tempDept.deptCode
)
SELECT * FROM tempDept;

posted @ 2017-05-09 21:51  草莓爸  阅读(306)  评论(0编辑  收藏  举报