Sorting hierachy data alphabetically in SQL Server 2005
0
Q:
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?
ASKED: Jul 1 2008  8:02 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
46795 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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.
Last Answered: Sep 9 2008  10:49 AM GMT by Mrdenny   46795 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



0