Hi Frndz,
Functionality: Run SP at a Once in Month
To achieve this task,
First Create one Table like SchedularDetail
When SP executes then in this table added Current DateTime.
After then second time when execute sp then check Date Month & Year Exists in this Scheduler Detail Table.
DatePart(month, SchedularDate) = DATEPART(month,getdate())
AND DatePart(year, SchedularDate) = DATEPART(YEAR,getdate())
If Date Exists then no need to Do Any operation
If Not Exist then do you logic.
Logic for SP:
CREATE PROCEDURE RunSchedular
AS
IF NOT EXISTS
(
Select
SchedularDate
from
SchedularDetail
where
DatePart(month, SchedularDate) = DATEPART(month,getdate())
AND DatePart(year, SchedularDate) = DATEPART(YEAR,getdate())
)
BEGIN
INSERT INTO SchedularDetail(SchedularDate) values (GETDATE())
Print 'SP LOGIC' -- Added Your Other Logic Here
END
ELSE
BEGIN
Print 'NOT DO ANY OPERATION' -- Not DO any operation
END
Execute for SP:
EXEC RunSchedular
Hope this helpful!
Thanks