• Skip to primary navigation
  • Skip to main content

ROB SYMONDS

  • Home
  • About

Get SQL Command Executing by SPID

2008-11-25 By Rob Symonds

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)

References

  • http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=59703
  • http://www.databasejournal.com/features/mssql/article.php/10894_2189761_1/Find-Out-What-Theyre-Doing-with-fngetsql.htm

Copyright © 2023 ยท Log in

  • RSS
  • Twitter
  • LinkedIn