SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


List job name which didn't run today but supposed to run today.


List job name which didn't run today but supposed to run today.

Author
Message
Alone
Alone
SSC Rookie
SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)SSC Rookie (45 reputation)

Group: General Forum Members
Points: 45 Visits: 287
Hi,

I have one query.i face one issue almost every day.

We have lot of scheduled jobs configured ,some of jobs can't start on time as server may down at that time.

Can i get the query which will show 'that job didn't run today '
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSCrazy Eights
SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)SSCrazy Eights (9K reputation)

Group: General Forum Members
Points: 9049 Visits: 7283
will this help:
;with LatestJobs AS
(SELECT Job_id, step_id, max(convert(varchar(8),run_date)+RIGHT('000000'+CONVERT(varchar(6), run_time),6)) As LastRun
from msdb.dbo.sysjobhistory
group by Job_id, step_id)
select j.job_id, j.name, next_run_date, next_run_time
from msdb.dbo.sysjobs j
join msdb.dbo.sysjobhistory h on h.job_id = j.job_id
join LatestJobs lj on lj.job_id = j.job_id and lj.step_id = h.step_id and lj.LastRun = convert(varchar(8),run_date)+RIGHT('000000'+CONVERT(varchar(6), run_time),6)
join msdb.dbo.sysjobschedules s on s.job_id = j.job_id
where h.run_date < s.next_run_date and h.run_time < s.next_run_time
and convert(date,convert(varchar(8),ISNULL(NULLIF(s.next_run_date,0),19000101)),112) < convert(date, getdate())



please do not hesitate to work and / or refine this further if it does not meet all your requirements

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
juancabrer
juancabrer
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 160
By the way, great post. I took the query provided and furthered refined it for jobs that have no history; you may have created a job yesterday that was supposed to run today. Also keep in mind that the query will return all columns and rows, so it's up to you to figure out which columns you want to see.


Select *
From msdb.dbo.sysjobs j with(nolock)
Inner Join msdb.dbo.sysjobschedules s with(nolock) on s.job_id = j.job_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 < s.next_run_date or h.run_date is null) and
(h.run_time < s.next_run_time or h.run_time is null) and
convert(date,convert(varchar(8),ISNULL(NULLIF(s.next_run_date,0),19000101)),112) < convert(date, getdate())

juancabrer
juancabrer
Grasshopper
Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)Grasshopper (15 reputation)

Group: General Forum Members
Points: 15 Visits: 160
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

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search