sql server 2008 - Delete all records from a table except latest N months records (sorted by id) -
can please me in solving this. need keep latest 3 months records in table.
table structure:
after purge table should
try this:
delete tablex inner join (select max(insertdt ) lastdate, id tablex group id) lastdates on lastdates.id = tablex.id insertdt < dateadd(m,-3,lastdates.lastdate)
Comments
Post a Comment