May 3, 2016 at 12:06 pm
I'm trying to create an Agent job that alternates it action each Saturday. In other words:
first week do X
next week do Y
next week do X
next week do Y
etc...
I can't figure out the date logic to accomplish this since a Saturday could fall on any date. Any ideas?
May 3, 2016 at 12:13 pm
two ideas.
can you just use two jobs, one scheduled to start on Saturday, and repeat each two weeks?
can you use a datemath and inline logic within the job step to determine if the inner command should run?
something like
IF DATEdiff(wk,0,getdate()) % 2 = 0 --or 1
BEGIN
EXEC(xproc)
END
IF DATEdiff(wk,0,getdate()) % 2 = 1 --or 0
BEGIN
EXEC(yproc)
END
Lowell
May 3, 2016 at 12:21 pm
Lowell beat me to the suggestion.
CREATE PROCEDURE Choose_Weekly_SP
AS
IF( SELECT DATEDIFF(wk, date_created, GETDATE()) % 2
FROM msdb.dbo.sysjobs
WHERE name = 'YourJob'
) = 0
EXECUTE ProcedureX;
ELSE
EXECUTE ProcedureY;
GO
May 3, 2016 at 12:27 pm
Thanks guys! That's exactly what I was looking for.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply