Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Show records for certain users within a company hierarchy 1

Status
Not open for further replies.

FesterSXS

Programmer
Feb 4, 2002
2,196
GB
Hi,

I am trying to get my head around this problem. I am designing an application that allows our sales force to login and do a multiple choice test to assess their knowledge of our company's products.

The problem I have is that I need to return test results for all people that sit beneath a particular director/manager within the company.

For example:
Code:
            o Director 1              o Director 2
           / \                       / \
          /   \                     /   \
   Mgr 1 o     o Mgr 2       Mgr 3 o     o Mgr 4
        / \   / \                 / \   / \
       o   o o   o               o   o o   o
Users  1   2 3   4               5   6 7   8

When a director or manager logs in, they will want to be able to see records for all the users that are beneath them. So Director 1 should only see records for Managers 1 & 2 and Users 1-4. Director 2 should only see records for Manager 3 & 4 and Users 5-8. Manager 2 should only see records for Users 3 & 4.

I am unsure of the best way to structure my users table in the database.

Should all users, managers, directors be in a single table? Managers need to take this test as well so they could also be considered as users.

How should I structure the SQL query to return all the relevant records based on the ID of the logged in user?

I'm not after a complete solution, just need some guidance really on where to start.

I asked this in the ASP.NET forum and I've had a suggestion that all the users/managers/directors should be in a single table:
Code:
ID     Name         ManagerID     UserLevelID
1      Director 1   NULL          3
2      Mgr 1        1             2
3      User 1       2             1
4      Mgr 2        1             2
Is this an efficient solution - and if so, how would the SQL look to retrieve all the records beneath Director 1 for example?

Thanks guys and girls.

Tony

Tony
---------------------------------------
 
OK, if you are using SQL Server 2000, and you are using the structure you mentioned in thread855-1450709, then here are some methods of retrieving the data:


There's easier methods of implementing this in SQL Server 2005 as well, however, I'd wait to see what other people suggest before going down this route as they may have other methods that are better than this.




-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top