Finding SQL Text of recently executed queries in SQL Server
we can find out SQL Text of recently executed queries in SQL Server by using below script. This script is very handy to find out queries history has been executed at SQL Server.
DECLARE @StartDate datetime, @EndDate datetime SELECT @StartDate='2020-02-08 20:02:29.007', @EndDate='2020-04-01 23:42:29.007' SELECT deqs.last_execution_time AS [Time], SUBSTRING( dest.TEXT,1,200) AS [Query] FROM sys.dm_exec_query_stats AS deqs CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
After execution of above script we get the output like below:-