Skip to content

Instantly share code, notes, and snippets.

@MagicAndi
Created May 18, 2017 15:40
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 MagicAndi/80740620413a0e62d9acfc344e252e56 to your computer and use it in GitHub Desktop.
Save MagicAndi/80740620413a0e62d9acfc344e252e56 to your computer and use it in GitHub Desktop.
Retrieve SQL queries from SQL Server. Taken from http://stackoverflow.com/a/15035060
SELECT execquery.last_execution_time AS [Date Time]
,execsql.text AS [Script]
FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
WHERE execsql.text LIKE '%<text to search for>%'
ORDER BY execquery.last_execution_time DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment