I need to delete records in a table if the current date is greater than the record creation date + a preset number of days (defined by @numberOfDays). I am using the following SQL statement but am not sure if it’s very efficient. Is there a better way?
I am using MS SQL 2008 server.
DELETE
FROM deviceManager.Test2
WHERE DATEADD(day, @numberOfDays, deviceManager.Test2.GeneratedAt_UTC) < SYSDATETIMEOFFSET()
@numberOfDays is an int with a value of 10