--Querying the 50 most CPU-intensive queries
SELECT TOP 50
DB_NAME(dbid) AS DBNAME,
OBJECT_NAME(objectid,dbid) as OBJECTNAME,
total_worker_time/execution_count/1000/1000 AS [CPU Average execution (sec)],
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) N'Execution Statements'
,st.text N'Full Words'
,total_worker_time/1000/1000 AS [Total CPU time consumed (seconds)]
,execution_count [number of runs]
,qs.total_worker_time/qs.execution_count/1000/1000 AS [average_execution_time_of_CPU(sec)]
,last_execution_time AS [last execution time]
,max_worker_time /1000/1000 AS [max_execution_time(sec)]
,total_physical_reads N 'total_physical_reads'
,total_logical_reads/execution_count N'number of logical reads per execution'
,total_logical_reads N'total_logical_reads'
,total_logical_writes N'total_logical_writes'
,*
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
WHERE last_execution_time> dateadd(minute,-100,getdate())
ORDER BY total_worker_time/execution_count DESC;
GO