SQL server - Find out who is executing the stored procedure from within it
To achieve this you can use SQL 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 article
Example:
CREATE PROCEDURE
AS
BEGIN
DECLARE @executor
SELECT @executor = SUSERNAME()
...
END
You can read more in this very useful articles:
This is a part of my Stackoverflow answer posted 18 Feb 2017