Home Forums SQL Server 2005 T-SQL (SS2K5) List job name which didn't run today but supposed to run today. RE: List job name which didn't run today but supposed to run today.

  • Okay, so I forgot to include the enabled flag for the schedule. Here goes version 2:

    Select *

    From msdb.dbo.sysjobs j with(nolock)

    Inner Join msdb.dbo.sysjobschedules js with(nolock) on js.job_id = j.job_id

    Inner Join msdb.dbo.sysschedules s with(nolock) on s.schedule_id = js.schedule_id

    Outer Apply(

    Select *,

    RankID = Dense_Rank() Over(Partition By job_id Order By convert(varchar,run_date)+ ' ' + RIGHT('000000'+CONVERT(varchar, run_time),6) Desc)

    From msdb.dbo.sysjobhistory with(nolock)

    where

    job_id = j.job_id) h

    where

    (h.RankID = 1 Or h.RankID Is Null) And

    (h.run_date < js.next_run_date or h.run_date is null) and

    (h.run_time < js.next_run_time or h.run_time is null) and

    convert(date,convert(varchar(8),ISNULL(NULLIF(js.next_run_date,0),19000101)),112) < convert(date, getdate()) and

    j.enabled = 1 and

    s.enabled = 1