views:

36

answers:

1

We have a bunch of T-SQL scripts dependent on today's date and when they run. If one doesn't run on the week it should, we end up temporarily setting the system time a day before, run the script, then set it back.

Is there anyway to temporarily set the system date for a script without changing the original script, like when you execute it or only for that session?

+1  A: 

You could store the actual date in a table / temp table. THen retrieve or update that date rather then making a call to GetDate().

JonH
Problem is the existing scripts call getdate() and we cannot change the existing scripts.
Dr. Zim
@Dr Zim - but if you run the script call getdate and then insert that date in the table you can then check. If there is a date to use the date in the table rather then getdate.
JonH
Without changing the existing code, how would you get the original code to use the date in a table?
Dr. Zim