What is a good system variable that will identify the user who ran the stored proc

  • I have a script that is run by various users using SSMS.

    This is a mess because I don't know who ran the script when and who ran it last and whether it got even completed.

    Can you tell me a variable that will give me the NT Userid of the user running the script ?

    Or if this is not possible can you suggest a unique variable like the session ID or something like that ? How can I get the value of it.

    But I do like if you could help me out with the former ( Which is the NT userid of the user ) .

    Please help

  • ORIGINAL_LOGIN()

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Can you put together a SQL statement and using the variable please ?

  • mw112009 (9/14/2015)


    Can you put together a SQL statement and using the variable please ?

    Gail gave you a function, not a variable. And it would help us if you posted the script and note where in the script you'd like to throw in the user name.

    I think you could just through it into the final SELECT, but as we have no idea what you're doing, there's no telling if that's a good answer for your situation or not.

    Brandie Tarvin, MCITP Database AdministratorLiveJournal Blog: http://brandietarvin.livejournal.com/[/url]On LinkedIn!, Google+, and Twitter.Freelance Writer: ShadowrunLatchkeys: Nevermore, Latchkeys: The Bootleg War, and Latchkeys: Roscoes in the Night are now available on Nook and Kindle.

  • mw112009 (9/14/2015)


    Can you put together a SQL statement and using the variable please ?

    uummm....

    select ORIGINAL_LOGIN()

    You could try reading Books Online (BOL), the manual that comes with sql server. It is understandable to not know about this function but even the most basic of research effort would provide the information you required.

    https://msdn.microsoft.com/en-us/library/ms189492.aspx

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply