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?
Use dateadd
DELETE
from tblmytable
where MyDateField > dateadd(yy, -1, GETDATE ())
Got it, this is the answer:
Delete tblmytable
where MyDateField > DATEADD(year, -1, GETDATE())
You can try this:
delete from table
where dateField > dateadd(yy, -1, getdate())
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.