Wednesday, March 7, 2012

Schedule Monthly Job -Skip first friday of every mon- Run on Mon

Hi,

I need to schedule a job that runs monthly on Mondays after the first friday on the month. How do i setup the schedule. let me know.

Thanks

There is no feature yet in SQL Server but I have posted a workaround from http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=707244&SiteID=1 which you can have a look. What is your job doing?

|||

One 'simple' way is to create two jobs.

For the Job you want to run on the first Monday following the First Friday of each month:

Set its' schedule to Monday of each week,

AND set the Job Schedule enabled to [False] (clear the Enabled checkbox on the Job Schedule properties form).

Verify that the Job itself is enabled.

Add a NEW last step that will (verify that the job will step into the last step.)

EXECUTE sp_update_jobschedule @.job_name = 'MyJobName', @.enabled= 0

--(0=FALSE) Check Books Online for full syntax

The Second job is scheduled to run on the FIRST Friday of each month. It has only one step, and that step will

EXECUTE sp_update_jobschedule @.job_name = 'MyJobName', @.enabled= 1

In operation, the Second Job will run on the first Friday of each month. It will then enable (Turn On) the first job so that the first job will then run on the next Monday. After the first job completes its' task, it will turn its schedule off and nothing will happen until the next month when it gets turned on again.|||I dont think i understand the above example. I need to run an SSIS package every month on a monday after the 1st friday of the month.|||

Arnie is saying that you create two jobs: The first one does what you need to do and then disables itself. This is scheduled to run every Monday. The second job runs on the first Friday of the month and just enables the first job.

The first job is initially disabled. Each Monday comes and the job doesn't run because it is disabled. The first Friday of the month comes and the second job enables the first job. On the next Monday, the first job runs because it's Monday and the job is enabled. After the Monday job completes, it disables itself so it won't run until the second job enables it again next month.

Thanks,

Steve

|||Thanks Steven.|||

Thanks for your responses. Will the below example do the same things

1) I will create a step1 with the below sql code and in my second step run the job. Configure the step 1 to quit job on failure and on success go to the next step. Let me know how it looks.

Thanks

declare @.dt datetime
set @.dt= DATEADD(wk, DATEDIFF(wk,4,dateadd(dd,2-datepart(day,getdate()),getdate())), 7)
if (getdate() <> @.dt)
BEGIN
SELECT @.dt, 'Monday After 1st Friday'
RAISERROR (N'Not a First Monday after Friday', 16,1)
END

No comments:

Post a Comment