Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

Help with DMV sys.dm_exec_query_stats

$
0
0

Below is one of Glenn Berry's SQL Performance queries for SQL 2005.  It gets Avg Elapsed Time of stored procedures in cache .  I need some help understanding what the query is doing. I want to get the name of the stored procedure into the aliased field [SP Name], but the query puts the definition of the stored procedure into [SP Name] instead of just the name of it.  When I run the query, [SP Name] looks something like...

    CREATE PROCEDURE [myschema].[mysp]  AS... rest of the SP definition.

The Glen Berry query is...

SELECT TOP(25) @@servername AS [Server_Name], getdate() AS [Date_Stamp],
qt.[text] AS [SP Name],
ISNULL(qs.total_elapsed_time/qs.execution_count, 0) AS [AvgElapsedTime],
qs.execution_count AS [Execution Count], qs.total_worker_time AS [TotalWorkerTime],
qs.total_worker_time/qs.execution_count AS [AvgWorkerTime],
ISNULL(qs.execution_count/DATEDIFF(Second, qs.creation_time, GETDATE()), 0) AS [Calls/Second],
qs.max_logical_reads, qs.max_logical_writes,
DATEDIFF(Minute, qs.creation_time, GETDATE()) AS [Age in Cache]
FROM sys.dm_exec_query_stats AS qs WITH (NOLOCK)
CROSS APPLY sys.dm_exec_sql_text(qs.[sql_handle]) AS qt
WHERE qt.[dbid] = DB_ID() -- Filter by current database
ORDER BY qs.total_elapsed_time/qs.execution_count DESC OPTION (RECOMPILE);

GO


Viewing all articles
Browse latest Browse all 12963

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>