;
with subDepartment
as ( select
BesonDepartmentID,
DepartmentName,
ParentBesonDepartmentID,
1 as HierarchyLevel
from dbo.[_Department]
where
BesonDepartmentID = 1
union all
select
A.BesonDepartmentID,
A.DepartmentName,
A.ParentBesonDepartmentID,
B.HierarchyLevel + 1 AS HierarchyLevel
from dbo.[_Department] A, subDepartment B
where A.ParentBesonDepartmentID = B.BesonDepartmentID
)

select * from subDepartment

posted on 2013-09-24 09:02  丢た壳の蜗牛  阅读(260)  评论(0编辑  收藏  举报