SQL Server: Get current user without domain
I know I can use
SELECT SUSER_SNAME() to get the current user name. But in an AD environment I would get the user including domain (e.g. “MyDomain\User”).
Is there any function to just receive the username excluding domain?
2 Solutions collect form web for “SQL Server: Get current user without domain”
SELECT nt_username FROM sys.sysprocesses WHERE spid = @@SPID
SELECT nt_user_name FROM sys.dm_exec_sessions WHERE session_id = @@SPID
select stuff(suser_sname(), 1, charindex('\', suser_sname()), '')