I'm using the following code to pull our top 20 queries (ordered by CPU):
SELECT TOP 20 qs.sql_handle
,qs.execution_count
,qs.total_worker_time AS [Total CPU]
,qs.total_worker_time / 1000000 AS [Total CPU in Seconds]
,(qs.total_worker_time / 1000000) / qs.execution_count AS [Average CPU in Seconds]
,qs.total_elapsed_time
,qs.total_elapsed_time / 1000000 AS [Total Elapsed Time in Seconds]
,st.TEXT
,qp.query_plan
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS st
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
ORDER BY qs.total_worker_time DESC
However, I'm seeing this:
Can anyone shed some light as to why the Query Plan and SQL Text are showing up NULL? Are they some sort of system process or external application? We are running SQL 2008 R2.
Thanks, as always, everyone!
Best Answer
In terms of the Statement Text being
NULL
, when selecting the text fromsys.dm_exec_sql_text
, thetext
value is NULL for encrypted objects.Check the
encrypted
value of the record fromsys.dm_exec_sql_text
.