Skip to content

Instantly share code, notes, and snippets.

@Apurer
Created April 10, 2024 09:55
Show Gist options
  • Save Apurer/55f4e55eccfa206dc1c1755e8d5d3f59 to your computer and use it in GitHub Desktop.
Save Apurer/55f4e55eccfa206dc1c1755e8d5d3f59 to your computer and use it in GitHub Desktop.
SELECT
TOP 10
qs.last_execution_time,
SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
((CASE qs.statement_end_offset
WHEN -1 THEN DATALENGTH(st.text)
ELSE qs.statement_end_offset
END - qs.statement_start_offset)/2) + 1) AS query_text
FROM sys.dm_exec_query_stats qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) st
ORDER BY qs.last_execution_time DESC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment