Showing posts with label SPID. Show all posts
Showing posts with label SPID. Show all posts

Get Last Running Query Based on SPID

Handy for tracking down long running queries,  use in conjunction with sp_who2



DECLARE @sqltext VARBINARY(128)
SELECT @sqltext = sql_handle
FROM sys.sysprocesses
WHERE spid = <SPID>
SELECT TEXT
FROM sys.dm_exec_sql_text(@sqltext)



Source: http://blog.sqlauthority.com/2009/07/19/sql-server-get-last-running-query-based-on-spid/