Home » Database » To get result from table under hierarchy

To get result from table under hierarchy

To get result from table under hierarchy.

</p>
<p>WITH MyCTE<br />
AS ( SELECT Id, ParentId, UserName, 1 as EmplyLevel<br />
FROM User<br />
WHERE User = '[email protected]'<br />
UNION ALL<br />
select E.Id, E.ParentID, E.UserName,EmplyLevel+1<br />
FROM User E<br />
INNER JOIN MyCTE ON MyCTE.EmployeeIndexId = E.SupervisorID<br />
WHERE E.User = '[email protected]'<br />
)<br />
SELECT * FROM MyCTE</p>
<p>

Leave a Reply

Subscribe

Join 901 other subscribers