Technical Article

Scheduling Jobs for Random / Multiple Dates

,

When you have a job that needs to be scheduled outside of the normal allowed schedules provided by em or ms, this works great...simple if statement that calls job by name on certain dates.

if datepart(month, getdate()) = 1
and datepart(d, getdate()) in (6,11)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 2
and datepart(d, getdate()) in (7,17)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 3
and datepart(d, getdate()) in (7,23)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 4
and datepart(d, getdate()) in (7,21)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 5
and datepart(d, getdate()) in (5,20)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 6
and datepart(d, getdate()) in (7,22)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 7
and datepart(d, getdate()) in (7,21)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 8
and datepart(d, getdate()) in (5,23)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 9
and datepart(d, getdate()) in (7,22)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 10
and datepart(d, getdate()) in (5,21)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 11
and datepart(d, getdate()) in (4,18)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

if datepart(month, getdate()) = 12
and datepart(d, getdate()) in (7,21)
EXEC msdb.dbo.sp_start_job @job_name = 'Job Name Here'

Rate

5 (3)

You rated this post out of 5. Change rating

Share

Share

Rate

5 (3)

You rated this post out of 5. Change rating