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

Identify user that called a stored procedure from within the SP

Status
Not open for further replies.

cconis

MIS
Mar 7, 2002
4
US
Hi, I have a need to get the name of the user logged in (who invoked) a stored procedure. I want to store settings that are user specific in a table. When the same user requests a setting, he needs to get his own settings. How can you tell who called a SP (or UDF) from within the procedure? Or is it not possible.

Thanks
 
If the connection to the db is that user's account you can use something like

@@user
 
Thanks for the quick response. Though, using @@User gives an error (Must declare the variable '@@User'). I ended up using the hostname instead of the user because I figured that one out.

-- get the users hostname
SET @UserHostname = (SELECT hostname from master.dbo.sysprocesses
Where spid = @@spid )


This accomplishes what I need, though I still wouldn't mind knowing how to get the @@User to work.

Thanks for your help,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top