Suggestion - Request RRS feed

  • Question

  • Hello,  

    On each query window, we can see the properties, regarding database we are connected to, username, duration of the last running query. 

    I would like to see also the DATE/TIME of last running.   For me it is important, since I leave this window open (when duration is so much) and I don`t know later on if the select I am seeing on screen is old or new. I keep opened the management studio for weeks normally on the server. 

    Gilberto H.

    Monday, May 14, 2018 7:28 PM

All replies

  • Hi Gilberto,

    I'm afraid there's no such direct way to show the last running Date/Time of queries in SQL Server Management Studio like the properties.

    But we can use DMV sys.dm_exec_query_stats which returns aggregate performance statistics for cached query plans in SQL Server to get the last running queries.

    Something like:

    SELECT deqs.last_execution_time AS [Time], dest.text AS [Query], dest.*
    FROM sys.dm_exec_query_stats AS deqs
    CROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest
    WHERE dest.dbid = DB_ID('msdb') //Your Database name
    ORDER BY deqs.last_execution_time DESC


    Xi Jin.

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, May 15, 2018 6:22 AM