About a year ago, I wrote blog post about SQL SERVER – 2005 – Last Ran Query – Recently Ran Query. Since, then I have received many question regarding how this is better than fn_get_sql() or DBCC INPUTBUFFER.
The Short Answer in is both of them will be deprecated.
Please refer to following update query to recently executed T-SQL query on database.
SELECT deqs.last_execution_time AS [Time], dest.TEXT AS [Query]
FROM sys.dm_exec_query_stats AS deqs
CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
ORDER BY deqs.last_execution_time DESC
Reference : Pinal Dave (http://blog.SQLAuthority.com)










Hi Pinal,
I ran this query it resulted with so many records.bit confusing. can you please let me know whats this query do?
Regards
Sanjeev Kumar
hi,
i tried above query i am getting output but i am not understanding output .
plz let me know in the query deqs means …..
Advance Thanks,
Rama krishna
hi ,
i have one dought about exception handling in sql server 2005,
i.e, if any error find in try block , is error display in front end or not
Hi Dave,
i wanted the recently executed query with user details with it. Is it possible that i can get these details.
please help me out.