I require is to have a single stored procedure which can execute
and show
“all SQL for the current connection which has previously run” and “not currently running”.
I have searched a lot about this and I am not able to find the answer. Please help me on this.
It is better to use the Profiler for this task.
But if you want a query in
SQL Server 2005+you can use system views sys.dm_exec_query_stats, whichreturns aggregate performance statistics for cached query plansbut only for the cashed plans, and sys.dm_exec_sql_text. Unfortunately they don’t have information about session ID so you can get only cashed queries of a server instance.