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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Employee Hierarchy Table Query

Author  Topic 

rc1138
Starting Member

35 Posts

Posted - 2010-11-30 : 17:12:27
Hi all,

Was wondering if someone can assist me with a Employee Hierarchy problem.

We currently have a table that only shows your direct manager

Table structure

ID|NAME|MGR_ID
1||Bob||2
2||Jeff||3
3||Carl||4

The new table as per the requirements need to look like this

ID|NAME|MGR1|MGR2|MGR3
1||Bob||2||3||4
2||Jeff||3||4
3||Carl||4

And so on

Having a bit of difficulty trying to figure out the logic for outputting a table similar to that. Any Help/Ideas would be greatly appreciated

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2010-12-01 : 01:46:56
create a seperate table for managers and employees.and then create seperate mapping table where you will be storing both employee id and manager id.now each employee id can have multiple manager id's.
if iam not wrong
Go to Top of Page

rc1138
Starting Member

35 Posts

Posted - 2010-12-01 : 08:37:05
Yes each employee can have multiple manager id's
Go to Top of Page

rc1138
Starting Member

35 Posts

Posted - 2010-12-01 : 08:39:44
I see so create a table for employees and managers containing just their names and ID's ?
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2010-12-01 : 11:20:16
exactly...after creating the two table then create a mapping table as i said.
Go to Top of Page

rc1138
Starting Member

35 Posts

Posted - 2010-12-01 : 17:13:23
I see thanks!
Go to Top of Page
   

- Advertisement -