Created
July 16, 2012 21:38
-
-
Save litodam/3125239 to your computer and use it in GitHub Desktop.
Retrieve "Query" Stats in SQL Server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- select * from sys.dm_exec_query_stats | |
SELECT QS.execution_count, | |
SUBSTRING(QT.TEXT, QS.statement_start_offset/2 + 1, | |
(CASE WHEN QS.statement_end_offset = -1 THEN LEN(CONVERT(NVARCHAR(MAX), qt.TEXT)) * 2 | |
ELSE QS.statement_end_offset END - qs.statement_start_offset)/2) AS query_text, | |
QS.total_elapsed_time, QS.last_elapsed_time, QS.min_elapsed_time, QS.max_elapsed_time, | |
QS.total_rows, QS.last_rows, QS.min_rows, QS.max_rows, | |
QS.total_worker_time / QS.execution_count AS avg_cpu_time | |
FROM sys.dm_exec_query_stats AS QS | |
CROSS APPLY sys.dm_exec_sql_text(QS.sql_handle) AS QT | |
ORDER BY QS.execution_count DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment