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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you grant permissions on rows? 1

  • Thread starter Thread starter j9
  • Start date Start date
Status
Not open for further replies.

j9

Programmer
Joined
Jun 6, 2001
Messages
90
Location
US
I have several stored procedures that currently accept the parameters 'year' and 'department'. Instead of using a parameter for 'department', I would like to determine the department based on the user's login. For instance, if John logs in, the stored procedure should only retrieve data from table1 where table2.department = English, but when Alice logs in, it should only retrieve data from table1 where table2.department=French. Is there any way to do this without creating different stored procedures for different departments?
 
The T-SQL function USER_NAME() returns the name of the current user. If you have a table with SQL Server user names and departments then it should be straightforward to write a WHERE clause that limits rows to the user's department. For example,

Code:
WHERE table1.department =
    (SELECT department FROM table2 WHERE emp_sql_user_name = USER_NAME())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top