with cte as ( select *, 0 as level from Organization where ParentID='' union all select d.*,level + 1 from cte c inner join Organization d on c.ID = d.ParentID ) select a.* from cte a
with cte as ( select *, 0 as level from Organization where ParentID='' union all select d.*,level + 1 from cte c inner join Organization d on c.ID = d.ParentID ) select a.* from cte a