views:

47

answers:

1

I've got a stored procedure which runs this to create a new ticket number:

 INSERT INTO [Test_DB42].[dbo].[TicketNumber]
  ([On], [By])

VALUES (CURRENT_TIMESTAMP, CURRENT_USER)

When I run with a user with db_datareader and execute permissions, I get the Active Directory samAccountName value which is what I want - this user gets access via an AD group which has a Login.

When I run with a user with sysadmin role it just says 'dbo'. This use has an explicit Login for their AD account.

Is there anyway to change this, or to return the AD samAccountName or SQL Login name?

+2  A: 

Use SUSER_SNAME() instead of CURRENT_USER

Mitch Wheat
Just for completeness ... there's also the functions SUSER_NAME() and USER_NAME() functions. It probably will be SUSER_SNAME() that's wanted, but in case that doesn't return quite the right thing.
Chris J
Thank you. That does exactly what I wanted.
serialhobbyist