Run a stored procedure only the last 3 days in a month How can I run a stored procedure only the last 3 days of a month using a T-SQL script?
Adding this script will help you to execute the SP only on the last three days of month.

Note: In the scheduler you make a schedule to execute it daily.

DECLARE @FromDate DATE
DECLARE @ToDate DATE
SELECT @FromDate=DATEADD(DD,-2,CAST(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1,0)) AS DATE)) --Last Date -2
SELECT @ToDate= CAST(DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1,0)) AS DATE) --Last Date of current month

IF (GETDATE() BETWEEN @FromDate AND @ToDate)
BEGIN

EXEC SP_YourSPName--------------------------Execute your SP here

END


I took query to get the last date of the month from https://blog.sqlauthority.com/2007/08/18/sql-server-find-last-day-of-any-month-current-previous-next/

DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,getdate())+1,0))

Same can be done using the query @Chris Rolliston mentioned in his comment.

DECLARE @Today DATE = GETDATE();
DECLARE @EOM DATE = EOMONTH(@Today);
IF (DAY(@EOM) - DAY(@Today) BETWEEN 0 AND 2)
EXEC SP_YourSPName;


Thanks!