Skip to content

Instantly share code, notes, and snippets.

@rally25rs
Created September 23, 2014 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rally25rs/cb58c6aa57a04d777efb to your computer and use it in GitHub Desktop.
Save rally25rs/cb58c6aa57a04d777efb to your computer and use it in GitHub Desktop.
SQL Server - Get all running queries
SELECT SUBSTRING(st.text, ( r.statement_start_offset / 2 ) + 1,
( ( CASE WHEN r.statement_end_offset <= 0
THEN DATALENGTH(st.text)
ELSE r.statement_end_offset END -
r.statement_start_offset ) / 2 ) + 1) AS statement_text ,
r.session_id,
r.status,
r.command,
r.cpu_time,
r.total_elapsed_time
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(sql_handle) st;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment