2

I want to create a new SQL job that runs the beginning of every quarter: 01/01 04/01 07/01 10/01 Is this possible? I know i can set it to run every 90 days but that's not exact. I am using SQL Server 2008. Thanks in advance!

2

You can't do this using the point-and-click UI, because it is primitive and inflexible, but you can set the job to run once a month, on the first, and put this in your job step:

IF DATEPART(MONTH, GETDATE()) IN (1,4,7,10)
BEGIN
  -- DO THE THINGS!
END

If you have multiple steps and want the whole job to exit, rather than having to put that logic in each step, you can reverse the condition and raise an error, and set the step properties to quit the job on error. If you want more graceful failure, you could add a step at the end that quits the job with success, and make that the next step for the first step on error.

IF DATEPART(MONTH, GETDATE()) NOT IN (1,4,7,10)
BEGIN
  RAISERROR('This is not the beginning of a quarter, silly.',11,1);
END
  • Perfect! I didn't see a way in the UI but this makes sense, thank you! – trbrink Sep 21 '15 at 21:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.