Get SQL Command Executing by SPID
Posted on November 25th, 2008 in Articles, Code | No Comments »
I’m sure there are other ways to do this but this is pretty easy:
DECLARE
@SPID INT,
@Handle binary(20),
@retVal varchar(8000)
SET
@SPID = 148
SELECT
@Handle=sql_handle
FROM
master..sysprocesses
WHERE spid = @SPID
SELECT
SqlCommand=convert(varchar(8000), [text])
FROM
::fn_get_sql(@Handle)