I would like to tun the Stored Procedures on the following dates.
1st sept 2020 1st Nov 2020 1st Dec 2020 1st Feb 2021 1st March 2021 1st May 2021 1st june 2021 1st august 2021
For that I have put the following code in the SQL Server Agent job
declare @dt datetime = getdate(); declare @time varchar(10) = convert(varchar(10), @dt, 108); if ((( @dt = '2020-09-01') or ( @dt = '2020-11-01' ) or ( @dt = '2020-12-01' ) or ( @dt = '2021-02-01' ) or ( @dt = '2021-03-01' ) or ( @dt = '2021-05-01' ) or ( @dt = '2021-06-01' ) or ( @dt = '2020-08-07' ) ) and ( @time between '00:00:00' and '23:59:59')) begin DECLARE @RC int EXECUTE @RC = [abc].[dbo].[sp1] end else -- out of allowed date range begin raiserror ('Not in the allowed date range', 15, 1); end
As today is 7th of August 2020. The if condition has today's date but still its not executing the SP, instead going into the else block and raises error. Any specific thing do i need to change?