| description | @@SPID (Transact-SQL) | |||||||
|---|---|---|---|---|---|---|---|---|
| title | @@SPID (Transact-SQL) | Microsoft Docs | |||||||
| ms.custom | ||||||||
| ms.date | 09/18/2017 | |||||||
| ms.prod | sql | |||||||
| ms.prod_service | database-engine, sql-database, sql-data-warehouse, pdw | |||||||
| ms.reviewer | ||||||||
| ms.technology | t-sql | |||||||
| ms.topic | reference | |||||||
| f1_keywords |
|
|||||||
| dev_langs |
|
|||||||
| helpviewer_keywords |
|
|||||||
| ms.assetid | df955d32-8194-438e-abee-387eebebcbb7 | |||||||
| author | julieMSFT | |||||||
| ms.author | jrasnick | |||||||
| monikerRange | >=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current |
[!INCLUDE sql-asdb-asdbmi-asa-pdw]
Returns the session ID of the current user process.
Transact-SQL Syntax Conventions
@@SPID
[!INCLUDEsql-server-tsql-previous-offline-documentation]
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';