Home Forums SQL Server 2005 Administering Querying the duration of the latest successful SQL Agent Job step RE: Querying the duration of the latest successful SQL Agent Job step

  • The core table for this is msdb.dbo.sysjobhistory. You can add a great deal of information by joining to other metadata tables in msdb, but this will get you started:

    SELECT SJ.[name], SJH.[step_id], SJH.[step_name], SJH.[run_date],

    SJH.[run_time], SJH.[run_duration]

    FROM msdb.dbo.[sysjobs] SJ LEFT JOIN

    msdb.dbo.[sysjobhistory] SJH ON SJ.[job_id] = SJH.[job_id]

    ORDER BY SJ.[name], SJH.[run_date] DESC, SJH.[step_id]

    - Tim Ford, SQL Server MVPhttp://www.sqlcruise.comhttp://www.thesqlagentman.com http://www.linkedin.com/in/timothyford