Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query Delete records older than 6 Months

Author  Topic 

Velnias
Yak Posting Veteran

58 Posts

Posted - 2009-03-11 : 06:15:51
Hi I am looking for a query to check if the "dateAdded" field is older than 6 months and if so then delete these records.

shaggy
Posting Yak Master

248 Posts

Posted - 2009-03-11 : 06:22:25
select dateadd(mm,-6, getdate())
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-11 : 06:23:58
Six months to the millisecond or 6 months to the day accuracy?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Velnias
Yak Posting Veteran

58 Posts

Posted - 2009-03-11 : 06:24:25
that will just select them ?

I was looking for delete query which compared my dateAdded column and check if it was older than 6 months
Go to Top of Page

Velnias
Yak Posting Veteran

58 Posts

Posted - 2009-03-11 : 06:24:58
I would say to day
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-11 : 06:24:58
DELETE
FROM Table1
WHERE dateAdded < DATEADD(MONTH, -6, GETDATE())



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Velnias
Yak Posting Veteran

58 Posts

Posted - 2009-03-11 : 06:26:00
Thanks Peso
Go to Top of Page
   

- Advertisement -