WITH tempDeptAS(SELECT deptCode,upDeptCode FROM dbo.bs_Dept WHERE deptCode='10.001'UNION ALLSELECT bs_Dept.deptCode,bs_Dept.upDeptCode FROM tempDeptINNER JOIN dbo.bs_Dept ON dbo.bs_Dept.upDeptCode=tempDept.deptCode)SELECT * FROM tempDept;