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 userMSDN article
  • CURRENT_USER() (it returns the name of the current userMSDN article
  • USER_NAME() (it returns a database user name from a specified identification numberMSDN article
  • ORIGINAL_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

Popular posts from this blog

SSIS - Script Task error: Exception has been thrown by the target of an invocation.

Don’t install Hadoop on Windows!

SSIS - script component DateTime Formats Implicit Conversion