Reputation: 934
Am I able to find out who is executing the stored procedure from within that procedure?
CREATE PROCEDURE
AS
BEGIN
DECLARE @executor
SET @executor = {query to find out}
END
Upvotes: 2
Views: 3021
Reputation: 37313
To achieve this you can use functions like
SUSER_NAME()
Function (it returns the login identification name of the user) MSDN articleCURRENT_USER()
(it returns the name of the current user) MSDN articleUSER_NAME()
(it returns a database user name from a specified identification number) MSDN articleORIGINAL_LOGIN()
(it Returns the name of the login that connected to the instance of SQL Server.) MSDN articleExample:
CREATE PROCEDURE
AS
BEGIN
DECLARE @executor
SELECT @executor = SUSERNAME()
...
END
You can read more in this very useful articles:
Upvotes: 3