递归查询数据库

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;

原文地址:https://www.cnblogs.com/feihusurfer/p/6832891.html