I am currently running a CTE query to recursively build an employee hierarchy from an employees table similar to what most recursive examples demonstrate. Where I am stuck
Are you looking for a query to return a variable number of columns, depending on the depth of hierarchy? Or just a concatenated string in one field?
Here's a minor change to your query that will get Eric and anyone above him in the hierarchy.
WITH employeeMaster
AS ( SELECT p.EmployeeID ,
p.MgrID ,
p.NAME
FROM Employees p
WHERE p.NAME = 'Eric'
UNION ALL
SELECT c.EmployeeID ,
c.MgrID ,
c.NAME
FROM employeeMaster cte
INNER JOIN Employees c ON c.EmployeeID = cte.MgrID
)
SELECT *
FROM employeeMaster m