Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
editech
Starting Member
4 Posts |
Posted - 2007-05-11 : 11:48:38
|
| I have an employee table .Employee table has columns employeeno and manager no ,manager name etc etc. Below is the table data EmployeeNo | EmployeeName| ManagerNo | MangerName001 | Ed | 005 | John002 | joe | 001 | Ed003 | Jim | 002 | Joe004 | Randy | 003 | Jim005 | John | | Since John is manager of Ed and Ed is manager of Joe and Joe is the manager of Jim and Jim is the manager of Randy , I want to display John as a manager to all since he at the top of hierarchy. How should I write the query to get the below resultsEmployeeNo | ManagerNo | Role001 | 005 | manager002 | 005 | manager003 | 005 | manager004 | 005 | manager |
|
|
dinakar
Master Smack Fu Yak Hacker
2507 Posts |
Posted - 2007-05-11 : 12:52:55
|
| Write a function that recursively looks for a record with ManagerNo = '' and get the EmployeeNum for that record.Dinakar NethiSQL Server MVP************************Life is short. Enjoy it.************************http://weblogs.sqlteam.com/dinakar/ |
 |
|
|
editech
Starting Member
4 Posts |
Posted - 2007-05-11 : 16:26:27
|
| Its just that I dont know how to write recursive SP. I need to pass an employeeno and it should return everybody below that person. |
 |
|
|
sshelper
Posting Yak Master
216 Posts |
|
|
|
|
|