tags:

views:

39

answers:

0

Possible Duplicate:
how can i write storec proc which to remove old records older than 90 days from table1 and table2

Hi All, i want to create two new stored procedures to remove records older than 90 days from tables DirStaging.Trr.FullEnrollmentImport and DirStaging.Trr.WeeklyMonthlyImport. The same stored procedure will remove all records from Dir.dbo.ErrorTable where there is not a record in Dir.Trr.FullEnrollment and Dir.Trr.WeeklyMonthly. Both the procedures will accept an input variable called @CleanupDays. This will be passed from the calling system. there is a field called EtlId in DirStaging.Trr.FullEnrollmentImport which i would have to use to get recent load of information. i mean, if i am loading thousand records then they would have same EtlId. so i guess i have to have @EtlId and @CleanupDays as input variables.

I tried something like moving all the data from the DirStaging.Trr.FullEnrollmentImport to temp table, truncate DirStaging.Trr.FullEnrollmentImport and apply condition on temp table to get recent records and move it back into DirStaging.Trr.FullEnrollmentImport. but i dont think thats the proper way of doing it.

is there any other way to create these stored procs.

Thanks and appreciate any help