Thursday, September 14, 2017

Get Last executed Query in SQL Server

SELECT
    equery.last_execution_time AS [Time],
    esql.TEXT AS [Query]
 FROM
    sys.dm_exec_query_stats AS equery
    CROSS APPLY sys.dm_exec_sql_text(equery.sql_handle) AS esql
WHERE esql.dbid = DB_ID('DatabasName')
ORDER BY
    equery.last_execution_time DESC

No comments:

Post a Comment

Search hierarchy for a match (TableALLGroup) X++

  Table1 ppt;  select firstonly ppt  order ItemCode, ItemRelation, AccountCode, AccountRelation where      (ppt.ItemCode == TableGroupAll::T...