Sorting hierachy data alphabetically in SQL Server 2005
I have a follow-up question to the article Navigate hierarchies using recursive common table expressions. I have an employee hierarchy that follows a similar pattern to the article, but I need to be able to sort my data alphabetically within each level. Do you have any advice on how to accomplish this?

Software/Hardware used:
ASKED: July 1, 2008  8:02 PM
UPDATED: September 9, 2008  10:49 AM

Answer Wiki:
Assuming that you use code similar to this: <pre>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 </pre> You can do an order by on the Level, then the LastName.
Last Wiki Answer Submitted:  September 9, 2008  10:49 am  by  Denny Cherry   64,520 pts.
All Answer Wiki Contributors:  Denny Cherry   64,520 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _