SELECT DISTINCT name by gnAMGr1

VIEWS: 7 PAGES: 1

									SELECT DISTINCT name
FROM   msdb.dbo.sysjobs j
WHERE j.job_id in
       (SELECT h.job_id
        FROM   msdb.dbo.sysjobhistory h
        WHERE j.job_id = h.job_id
          AND h.run_status in (4)
        -- run_duration is Elapsed time in the execution
        -- of the job or step in HHMMSS format
        -- (200 = 2 minutes):
          AND run_duration > 200
          AND h.job_id in (SELECT TOP 1 h2.job_id
                            FROM msdb.dbo.sysjobhistory h2
                            WHERE h.job_id = h2.job_id
                            ORDER BY run_date, run_time desc
                          )
        )

--   Job   statuses in sysjobhistory:
--   0 =   Failed
--   1 =   Succeeded
--   2 =   Retry
--   3 =   Canceled
--   4 =   In progress

								
To top