Monday, March 14, 2005

 
List of Subordinates

/*
Get the List of Subordinates and their managers
*/


CREATE PROC dbo.getSubordinates
(@EmpId int)
AS
BEGIN
SET NOCOUNT ON
DECLARE @Hkey bigint

SELECT @HKey = Hkey
FROM EmpHierarchy
WHERE EmpId = @EmpId


SELECT A.EmpId, A.EmpName AS Employee, C.EmpName As Manager
FROM EmpHierarchy A
LEFT JOIN EmpHierarchy C
ON A.ManagerId = C.EmpId
WHERE A.Path % @HKey = 0
ORDER By A.Path

END

GO

Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?