Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Created January 9, 2015 18:33
Show Gist options
  • Select an option

  • Save JohnLBevan/023913af3a2a0969d480 to your computer and use it in GitHub Desktop.

Select an option

Save JohnLBevan/023913af3a2a0969d480 to your computer and use it in GitHub Desktop.
Get Recently Executed SQL (in date range / ignoring some common bits)
--get sql statements just executed; filtering out common junk
SELECT top 100 deqs.last_execution_time AS [Time]
, dest.TEXT AS [Query]
, deqs.*
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
where deqs.last_execution_time between '2015-01-08 16:20:00' and '2015-01-08 16:22:00'
and total_logical_writes > 0
and dest.TEXT not like '--SQL%'
and dest.TEXT not like '%FETCH%'
and dest.TEXT not like '%SYSSERVERSESSIONS%'
and dest.TEXT not like '%BATCH%'
ORDER BY deqs.last_execution_time DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment