I want to create a two stored procedures that will remove records older than N days from a stgging database.
Both stored proc will call in a package to cleanup data older than N days.
Stored proc A will remove records from table A.Fullimport & stored proc B will remove records from table B.weeklyimport.
The same stored proc will remove all records from error table where there is not a record in table x and table Y.
Both stored proc will accept input variable @Cleanupdays.
Basically, you’d have to write something like:
or something like that – without the exact table structures, it’s really hard to get this totally correct…..
The
DATEDIFFfunction can give you the difference between two dates in various units – e.g. in days, as you want it (could also be weeks, months, year etc.). All you basically have to do is delete all the rows that have aDATEDIFFto today’s date that is greater than the value of@CleanupDayspassed into the stored procedure.I don’t quite understand what you meant about the error table…. you might need to clarify that a bit…