My database has alot of records recording the datetime various actions are or will be taken. In order to test the database properly, i want to move all of those further into the past, by 6 months, a year etc (As opposed to changing the system time). How can i achieve this with a stored procedure, paramaterised by number of days?
(Bonus points if you also include other date/time types such as datetime2)
To be clear, i’m looking for something that will update all columns in all tables dynamically.
Seems pretty simple…
Call this like so:
or whatever you need …
The
DATEADDfunction should work with any date type in SQL Server 2008 or newer – if you apply it to aDATETIME2, you’ll get back a newDATETIME2But this seems too simple for Stackoverflow – what am I missing here??
Update: if you want to do this globally, across all tables and all date-related columns in your entire database – you can use a cursor-based approach something like this: