Link to home
Start Free TrialLog in
Avatar of Thandava Vallepalli
Thandava VallepalliFlag for United States of America

asked on

how to update a table recursively sql server 2005?

Hello Experts,


There is an Employee table with (Empid, empname, ManagerID, salary)

i need toi update salary for all employees of s perticular manager? I am trying with recursive CTE syntax. But no luck.

Could you please help me on this?

Thanks,
itsvtk



Avatar of Aneesh
Aneesh
Flag of Canada image

why cant you get the ids of all the employee reporting to the manager

;WITH CTE_EmpList ( ManagerID )
AS (
-- anchor members
SELECT e.ManagerID
FROM Employee e
WHERE ManagerID = @managerID

UNION ALL
-- recursive members
SELECT e.ManagerID
FROM Employee e
INNER JOIN CTE_EmpList d ON e.ManagerID = d.EmployeeID
)
Do you need recursion? What about:

UPDATE Employee SET ...
WHERE ManagerID = @MgrID
ASKER CERTIFIED SOLUTION
Avatar of Rob Farley
Rob Farley
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is it possible to explain with some sample data and how do you want to update?