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
 User Parameter

Author  Topic 

gavakie
Posting Yak Master

221 Posts

Posted - 2012-01-04 : 12:00:40
I need to write a code based of a user id so that say a Manger can see everything. A supervisor could see only his teams data, and a rep could see only his data. Can anyone help on this?

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-04 : 12:03:46
sure..how do you know who's data is who(m)'s?

Got DDL?

And sample Data

And then who can see what?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

gavakie
Posting Yak Master

221 Posts

Posted - 2012-01-04 : 12:23:27
It basically has a unique ID for each employee that has there supervisor listed as well.

EMPID EMPNAME SUPNAME Manager
1 a x q
2 b x q
3 c z q
4 d z q
5 e x q
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-01-04 : 12:25:10
seems like what you need is common table expression which recurses and gives you entire hierarchy

http://msdn.microsoft.com/en-us/library/ms186243.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -