• I agree with Leo, the sysjobs and sysjobhistory tables can be quite useful. Here's a query I wrote which will return the average, max, min, range and standard deviation of step runs in milliseconds over the course of given date range for a given job. Very useful when determining which parts of a job are taking a long time.

    SELECTAVG(sjh.run_duration) AS avg_run_duration_ms,

    MAX(sjh.run_duration) AS max_run_duration_ms,

    MIN(sjh.run_duration) AS min_run_duration_ms,

    MAX(sjh.run_duration) - MIN(run_duration) AS range_run_duration_ms,

    ROUND(STDEV(sjh.run_duration),2) AS stdev_run_duration_ms,

    sjh.step_id, sjh.step_name

    FROMsysjobhistory sjh

    INNER JOIN sysjobs sj ON sjh.job_id = sj.job_id

    INNER JOIN SANDBOX.dbo.Numbers n ON sjh.step_id = n.Number

    WHERE sj.name = 'xxx' -- put job name here

    AND sjh.run_date BETWEEN 20120616 AND 20120716 -- put date range here

    AND step_id <> 0

    GROUP BY sjh.step_id, sjh.step_name

    ORDER BY step_id

    ---

    Note to developers:
    CAST(SUBSTRING(CAST(FLOOR(NULLIF(ISNULL(COALESCE(1,NULL),NULL),NULL)) AS CHAR(1)),1,1) AS INT) == 1
    So why complicate your code AND MAKE MY JOB HARDER??!:crazy:

    Want to get the best help? Click here https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help (Jeff Moden)
    My blog: http://uksqldba.blogspot.com
    Visit http://www.DerekColley.co.uk to find out more about me.