Quantcast
Channel: T-SQL Code Examples – SQLSERVERLEARNER
Viewing all articles
Browse latest Browse all 27

TSQL Script to fetch the code that is executed by an SPID

$
0
0

Below is the TSQL Script to fetch the code that is executed by an SPID

DECLARE @sql_handle AS VARBINARY (1000)
 
SELECT @sql_handle = SQL_HANDLE
FROM   sys.sysprocesses WITH (NOLOCK)
WHERE  spid = 56; --To Do: Update with SPID OF the Process
 
SELECT *
FROM   sys.dm_exec_sql_text (@sql_handle)

Viewing all articles
Browse latest Browse all 27

Trending Articles