Do you need recursion? What about:
UPDATE Employee SET ...
WHERE ManagerID = @MgrID
Main Topics
Browse All TopicsHello 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
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
If you need the whole Organisation Structure under that manager, then try:
--Make sure the previous query has ended in a semi-colon.
WITH EmployeesToUpdate AS (
--Start with the Manager themself
SELECT @MgrID AS EmployeeID
UNION ALL
--And now pull in the people that report to them (recursively)
SELECT e.EmployeeID
FROM Employee e JOIN EmployeesToUpdate m
ON e.ManagerID = m.EmployeeID
)
UPDATE e SET ....
FROM Employee e JOIN EmployeesToUpdate u
ON e.EmployeeID = u.EmployeeID
;
Business Accounts
Answer for Membership
by: aneeshattingalPosted on 2009-07-07 at 18:25:01ID: 24799907
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
)