• Try this

    If not exactly what you need, it should get you some ideas at least.

    select job_name, MAX(run_datetime) AS run_datetime, MAX(run_duration) AS run_duration,t.stop_execution_date

    from

    (

    select job_name, run_datetime,t.stop_execution_date,

    SUBSTRING(run_duration, 1, 2) + ':' + SUBSTRING(run_duration, 3, 2) + ':' +

    SUBSTRING(run_duration, 5, 2) AS run_duration

    from

    (

    select DISTINCT

    j.name as job_name,ja.stop_execution_date,ja.start_execution_date AS run_datetime,

    --run_datetime = CONVERT(DATETIME, RTRIM(run_date)) +

    -- (run_time * 9 + run_time % 10000 * 6 + run_time % 100 * 10) / 216e4,

    run_duration = RIGHT('000000' + CONVERT(varchar(6), run_duration), 6)

    from msdb.dbo.sysjobhistory h

    inner join msdb..sysjobs j

    on h.job_id = j.job_id

    CROSS APPLY (SELECT MAX(stop_execution_date) AS stop_execution_date,MAX(start_execution_date) AS Start_execution_date

    FROM msdb.dbo.sysjobactivity ja

    WHERE ja.job_id = j.job_id) ja

    WHERE j.name NOT LIKE 'Backup%'

    AND j.name NOT LIKE 'Cleanup%'

    AND j.name NOT LIKE 'Shrink%'

    AND j.name <> 'WMI_Disk_Space_Notification'

    AND j.name <> 'syspolicy_purge_history'

    ) t

    ) t

    WHERE run_dateTime >= '2013-03-08' AND run_dateTime <= '2013-03-11'

    GROUP BY job_name,t.stop_execution_date

    order by stop_execution_date DESC,job_name, run_datetime

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events