Skip to content

Instantly share code, notes, and snippets.

@ststeiger
Last active March 21, 2024 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ststeiger/04ed8331a0af2920271d81f5595bfe71 to your computer and use it in GitHub Desktop.
Save ststeiger/04ed8331a0af2920271d81f5595bfe71 to your computer and use it in GitHub Desktop.
Find past executed queries by text in MSSQL
SELECT
t.[text], qs.creation_time
FROM sys.dm_exec_cached_plans AS p
CROSS APPLY sys.dm_exec_sql_text(p.plan_handle) AS t
JOIN sys.dm_exec_query_stats qs ON p.plan_handle = qs.plan_handle
-- WHERE t.[text] LIKE N'%something unique about your query%';
WHERE t.[text] LIKE N'%CTE%'
-- AND t.text LIKE '%APP-APERTUR%'
ORDER BY qs.creation_time DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment