T-SQL to list processes and their running sql

select sp.spid, sp.status, sp.blocked, sp.hostname, db_name(sp.dbid), object_name(objectid), qt.text
from sys.sysprocesses sp
cross apply sys.dm_exec_sql_text(sp.sql_handle) qt
where sp.status <> 'sleeping'

Credits to Phil Hendry

0 comments: