Discussion ForumHow to get last executed query in SQL Server
1 Answers
vinod palne Staff answered 1 year ago
 

SELECT t2.TEXT AS [Query],
t1.execution_count [Count],
t1.last_execution_time AS [Time]
FROM sys.dm_exec_query_stats AS t1
CROSS APPLY sys.dm_exec_sql_text(t1.sql_handle) AS t2
ORDER BY t1.last_execution_time DESC