Run SQL Job monthly at day 16. If it's a weekend, run it in the next business day ( dont care if is a holiday) I need to run a job every day 16. But if it is &quot;saturday&quot; or &quot;sunday&quot; it must run in the next business day.
I don't care if it is holidays or not. I just need to run it.
I could do something like this and separete it on steps, and only pass to the next step if it runs with no error:
--Step 1 - Verify if it is 16
IF  day(getdate()) &lt;&gt; 16
    RAISERROR ('Job runs only day 16.',16,1) 

--Step 2 - verify if its saturday of sunday
IF  DATEPART(weekday,getdate()) IN ( 7,1 )
    RAISERROR ('Job will run on the next business day.',16,1)

I would create 2 steps with these queries, but this is not going to work since, lets say the next business day is 18, the first step will raise an error.
Is there a way to schedule something like this?
It's not beautiful, but you could wrap all of your conditions into a CASE like so:
DECLARE @IsGood bit;
SET @IsGood = SELECT CASE WHEN DAY(GETDATE()) = 16 AND DATEPART(WEEKDAY, GETDATE()) NOT IN (1, 7) THEN 1
                          WHEN DAY(GETDATE()) IN (17, 18) AND DATEPART(WEEKDAY, GETDATE()) = 2 THEN 1
                          ELSE 0 END;

IF @IsGood &lt;&gt; 1
    RAISERROR ('Nope. Not today.', 16, 1); 

Throw that into a scheduled job that runs on the 16th, 17th, and 18th of every month, and you'll be good.