Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the actual CURRENT_USER for a dbo in SQL 2005?

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?

like image 458
serialhobbyist Avatar asked Sep 27 '09 06:09

serialhobbyist


1 Answers

Use SUSER_SNAME() instead of CURRENT_USER

like image 56
Mitch Wheat Avatar answered Oct 02 '22 23:10

Mitch Wheat