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?

  • Sql automatically update
  • How to declare variables in T-SQL scripts that are common across multiple scripts being run
  • SQL Server - COALESCE WHEN NOTHING RETURNS , GET DEFAULT VALUE
  • Unique index or unique key?
  • Full text search: how to sort by relevance?
  • Full text search feature not available from installation wizard
  • 2 Solutions collect form web for “SQL Server: Get current user without domain”

    SELECT nt_username FROM sys.sysprocesses WHERE spid = @@SPID
    

    or

    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.