Deleting records with a date older than 3 days to minimize 3-day work?

Before executing the sql secret command, I wanted to perform a health check.

I am trying to delete records with a date value of [ LoadDt ] older than 3 days, and my code is:

 delete IntraDayStats where DATEDIFF(dd, LoadDt, dateadd(d,-3, getdate()) ) >= 3 

I want to assign this as a sql job so that the IntraDayStats table IntraDayStats a 3 day history. Work will be performed at night.

+6
sql-delete datediff sql-server-2005
source share
1 answer
 where DATEDIFF(dd, LoadDt, dateadd(d,-3, getdate()) ) >= 3 

cannot be matched (index will not be used), use

 where LoadDt < getdate()- 3 

Next time, if you want to check, do DELETE a SELECT and see that you come back

+9
source share

All Articles