Return the Current Login Name in SQL Server (T-SQL)

You can use the SUSER_NAME() function to see the login name that you’re currently using to access SQL Server.

This function returns returns the login identification name of the user. It also allows you to get the login name of any other user, based on their login identification number.

Example

Here’s how to get the current user.

SELECT SUSER_NAME();

Result:

sa

In this case I was logged in as sa.

Return a Specific User

Here’s an example of getting the login identification name for another user.

SELECT SUSER_NAME(262);

Result:

Rick

Include the Current Workstation

You can also use HOST_NAME() to return your current workstation ID.

SELECT 
  HOST_NAME() AS HOST_NAME,
  SUSER_NAME() AS SUSER_NAME;

Result:

+---------------------+--------------+
 | HOST_NAME           | SUSER_NAME   |
 |---------------------+--------------|
 | Bobs-MacBook-Pro    | Bob          |
 +---------------------+--------------+