SQL @@SPID

SQL @@SPID is one of the Configuration Functions, which will return the session ID that currently used. Syntax behind this is

@@SPID

SQL @@SPID Example

The below code snippet will show the SP ID and their respective login name that is currently being used by SQL.

SELECT @@SPID AS 'SP ID', 
       SYSTEM_USER AS 'Login Name', 
       USER AS 'User Name';
SQL @@SPID 1

Let us use another SQL Server login to enter into SQL Server Management Studio. Now, you can see, it is displaying different SP ID, and login name

SQL @@SPID 2

If you don’t know the list of available users and their IDs, then use sp_who system stored procedure.

SQL @@SPID 3