Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi all,
Based on a recent post where most of my problems were solved, i am still facing one tiny challange: Hiererchy.
The situation: I have a table of employees. Each employee has a manager. Each manager can have another manager:
EmployeeID | Name | ManagerID |
---|---|---|
1 | Smith | 5 |
2 | Miller | 5 |
3 | Gold | 2 |
4 | Stone | 5 |
5 | Boss | 5 |
What i need to do is to create a link table in the following format based on the employee table above:
ManagerID | EmployeeID |
---|---|
1 | 1 |
2 | 2 |
3 | 2 |
3 | 3 |
4 | 4 |
5 | 1 |
5 | 2 |
5 | 3 |
5 | 4 |
5 | 5 |
How to read the table above:
- generally every employee is also a manager - even if the peron has no people below, the person is at least his own manager
- each manager must be able to see his own as well as the IDs of the people below. For ManagerID = 3 this means: 2 (the one person below; 3 as himself)
So far so good - but what i am struggeling on is to create the data for a manager that has employees and where one or more of these employees also have employees; like ManagerID = 5. Manager 5 must be able to see all Employee IDs as he is direct manager (for IDs1, 2, 4) and indirect manager (for ID 3).
Hope, my problem became clear. thanks a lot for some hints!
Hi
Please consider using HIERARCHY function. It automaticaly parses parent-child relations.
Cheers
Darius