I have a table Emp. Each employee is assigned to a manager and each manager is assigned to another manager above the employee. This level may go upto 4 or 5 levels. Some employees may not have a manager assigned to them (for instance test employees and also the department head). The data is stored in a table called Emp. Each employee has a primary key and the manager also has a primary key as an employee. The table is designed such a way that for each employee who is assigned a manager is idendified with the manager's primary key as (Foreign Key) for that employee row.
Emp_Pk Emp_MgrEmpFk EmpName
134 23 San
254 23 David
23 56 Frank
56 11 Rob
11 Null Jessica
In this example the employee Jessica is not associated with any manager. So I want to pull data showing Jessica at the top level and below is Rob and below Rob Frank and Below Frank I want to show San and David.
I need to write a sql query for this.
Can you guys help me out?
I am using MS SQL server 2003.
Thanks
Programmer
Emp_Pk Emp_MgrEmpFk EmpName
134 23 San
254 23 David
23 56 Frank
56 11 Rob
11 Null Jessica
In this example the employee Jessica is not associated with any manager. So I want to pull data showing Jessica at the top level and below is Rob and below Rob Frank and Below Frank I want to show San and David.
I need to write a sql query for this.
Can you guys help me out?
I am using MS SQL server 2003.
Thanks
Programmer