Skip to content

Instantly share code, notes, and snippets.

@weeksdev
Created June 20, 2019 15:52
Show Gist options
  • Save weeksdev/b45c9127a9222038ba2857f3b876ca28 to your computer and use it in GitHub Desktop.
Save weeksdev/b45c9127a9222038ba2857f3b876ca28 to your computer and use it in GitHub Desktop.
SELECT
cast(r.total_elapsed_time as decimal(18,2)) / 1000 / 60,
r.session_id
,st.TEXT AS batch_text
,SUBSTRING(st.TEXT, statement_start_offset / 2 + 1, (
(
CASE
WHEN r.statement_end_offset = - 1
THEN (LEN(CONVERT(NVARCHAR(max), st.TEXT)) * 2)
ELSE r.statement_end_offset
END
) - r.statement_start_offset
) / 2 + 1) AS statement_text
,qp.query_plan AS 'XML Plan'
,r.*
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS st
CROSS APPLY sys.dm_exec_query_plan(r.plan_handle) AS qp
ORDER BY cpu_time DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment