SQL Server Job – How to Create a SQL Job to Run on Specified Dates

sql serversql-server-2008

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!

Best Answer

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