Collecting Username in driver table

  • Hello,

    I have the following constraint on my driver table, and records are inserted via a stored procedure but the xUserName is not populated by this. I was expecting that the xUsername would be populated automatically by the system grabbing the user name of the person kicking off the SP. I see a bunch of NULLS in my driver table. Why would this be, do I use the wrong function?

    ALTER TABLE [dbo].[tblProcessingQueue] ADD DEFAULT (suser_sname()) FOR [xUserName]

    thanks a bunch!

  • forgot to mention, we use 'windows authentication'

    what is the difference between SYSTEM_USER and suser_sname?

    thanks again

  • Check BOL for a definition of:

    SUSER_SNAME function

    SYSTEM_USER function

    BOL clearly state what the functions do and it is easy to identify the differences.

    For better, quicker answers on T-SQL questions, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

  • decided to use COALESCE() function to improve coverage 😉

    --> coalesce(suser_sname(),suser_sname(),suser_name())

Viewing 4 posts - 1 through 3 (of 3 total)

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