Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Stored Procedure- Multil level employee hierarchy in the same row

$
0
0

I have an employee table where I have employee details  which includes the following properties:

EmployeeID, EmployeeName, ManagerID, DesignationCode.

ManagerID maps to EmployeeID in the Emp table. DesignationCode is to identify the employee designation.

The topmost person of the organization could be identified by : whose DesignationCode is 'XX' and ManagerID=EmplyeeID.

Here, 'XX' is fixed and will not change.

Also, we know there could be a maximum of 10 level for each hierarchy.

Example: Employee1 reports to Manager1 who reports to Manager2 who reports to Manager 3 ..... who reports to ManagerN.

I need to pull a hierarchy in the below format:

EmpName  MgrName0  MagrName1  MgrName2 ..........MgrName7  MgrNameMgrName9

SAMRAT                                                                                                  XXX                XXX

SUDHAKAR                                                                     XXX                 XXX                XXX

SATESWAR                                                                                             XXX                XXX

SRINI               XXX                  XXX                                XXX                 XXX                XXX                                                                                     

IMPORTANT POINT: We need to identify the reporting hierarchy level for each employee's manager and then place the manager names accordingly based on the columns.

Example:

If an employee's manager has only 1 reporting manager(who is at top level), then he would be placed at the column "ManagerName8" and ManageName9 would be the topmost employee of the organization

In short, we need to identify the reporting level at which the employees manager belongs and then start filling the columns values for that row ( employee details)

I am stuck and unable to do the same. Please help.

Thank you.



Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>