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?

  • JDBC connection hangs with no response from SQL Server 2008 r2
  • SQL: Using Top 1 in UNION query with Order By
  • Combine rows when the end time of one is the start time of another
  • how to catch NULL values using case statement
  • SQL Server 2008 OPENROWSET permission issue
  • Create SQL identity as primary key?
  • 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()), '')
    MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.