MSDB - How to Link Steps to Jobs

  • In dbo.sysjobhistory table, we get list of all the jobs and step execution history. But how do we group the steps related to a particular execution? Is there any easy way of doing this?

  • If you are looking for the job name, In sysjobhistory table you have a field name "Job_ID" if you join it with "sysjobs" Table you get the name.

    Something like  this :


    select j.name, jh.*
    from sysjobhistory jh
    join sysjobs j on jh.job_id = j.job_id
    order by job_id,instance_id

  • This article (http://www.sqlservercentral.com/articles/Agent+jobs/101563/) might be of interest.

  • rka - Thursday, September 7, 2017 5:35 PM

    In dbo.sysjobhistory table, we get list of all the jobs and step execution history. But how do we group the steps related to a particular execution? Is there any easy way of doing this?

    A quick and easy way to get those grouped together when just querying sysjobhistory is to use an order by:
    ORDER BY job_id, run_date, run_time, step_id
    The step id is a bit odd since the job outcome "step" listed isn't really a step and the id for that is 0. You can use where step_id <> 0 if you want to exclude that one. But you will want the job outcome step if looking for the duration of the entire job.

    Sue

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply