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

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...