Reputation: 2657
I'm using SQL Server 2012. I need to delete data that is greater than this time last year.
So far example, delete any records greater than 28/11/2015.
This is rolling though and will be part of a SP that will run each day, so everyday it checks the current date and deletes. What is the best way to do this?
DELETE tblmytable
where MyDateField > GETDATE ()
How do I change to say > Today from last year?
Upvotes: 0
Views: 312
Reputation: 1
You can try this:
delete from table
where dateField > dateadd(yy, -1, getdate())
Upvotes: -2
Reputation: 2657
Got it, this is the answer:
Delete tblmytable
where MyDateField > DATEADD(year, -1, GETDATE())
Upvotes: 0
Reputation: 11205
Use dateadd
DELETE
from tblmytable
where MyDateField > dateadd(yy, -1, GETDATE ())
Upvotes: 5