Assuming that you use code similar to this:
WITH EmployeeCTE
AS
(
SELECT
EmployeeID,
1 AS Level
FROM HumanResources.Employee
WHERE ManagerID IS NULL
UNION ALL
SELECT
E.EmployeeID,
x.Level + 1 AS Level
FROM HumanResources.Employee E
JOIN EmployeeCTE x ON x.EmployeeID = E.ManagerID
)
SELECT
EmployeeID,
Level
FROM EmployeeCTE
You can do an order by on the Level, then the LastName.
Discuss This Question: