| title | @@SPID (Transact-SQL) | Microsoft Docs | |||||||
|---|---|---|---|---|---|---|---|---|
| ms.custom | ||||||||
| ms.date | 03/14/2017 | |||||||
| ms.prod | sql-non-specified | |||||||
| ms.reviewer | ||||||||
| ms.suite | ||||||||
| ms.technology |
|
|||||||
| ms.tgt_pltfrm | ||||||||
| ms.topic | language-reference | |||||||
| f1_keywords |
|
|||||||
| dev_langs |
|
|||||||
| helpviewer_keywords |
|
|||||||
| ms.assetid | df955d32-8194-438e-abee-387eebebcbb7 | |||||||
| caps.latest.revision | 39 | |||||||
| author | BYHAM | |||||||
| ms.author | rickbyh | |||||||
| manager | jhubbard |
[!INCLUDEtsql-appliesto-ss2008-all_md]
Returns the session ID of the current user process.
Transact-SQL Syntax Conventions
-- Syntax for SQL Server, Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse
@@SPID
smallint
@@SPID can be used to identify the current user process in the output of sp_who.
This example returns the session ID, login name, and user name for the current user process.
SELECT @@SPID AS 'ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name';
[!INCLUDEssResult]
ID Login Name User Name
------ ------------------------------ ------------------------------
54 SEATTLE\joanna dbo
This example returns the [!INCLUDEssDW] session ID, the [!INCLUDEssNoVersion] Control node session ID, login name, and user name for the current user process.
SELECT SESSION_ID() AS ID, @@SPID AS 'Control ID', SYSTEM_USER AS 'Login Name', USER AS 'User Name';