Skip to content

Instantly share code, notes, and snippets.

@Otterpohl
Created May 13, 2022 14:48
Show Gist options
  • Save Otterpohl/3761ca149df39d44baa5c902b5184728 to your computer and use it in GitHub Desktop.
Save Otterpohl/3761ca149df39d44baa5c902b5184728 to your computer and use it in GitHub Desktop.
Get a query plan using some of the query text
SELECT TOP 10
d.name,
st.text,
qs.creation_time,
qs.execution_count,
qs.total_worker_time,
qs.total_elapsed_time,
qs.total_logical_reads,
qs.total_physical_reads,
qp.query_plan,
qs.plan_handle
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.plan_handle) AS st
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle) AS qp
INNER JOIN sys.databases AS d
ON st.dbid = d.database_id
WHERE st.text LIKE '%From vMIPL_Appraisal_Details%'
OPTION (RECOMPILE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment