Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting old Records

Status
Not open for further replies.

bjr149

Programmer
Jul 18, 2005
26
US
I need to have a method in place to delete old records off of a staging table. I have this code that works for records that are over 4 months old

delete from vcsv_payment_stage
where time_moved < dateadd(mm, -4, getdate())


I want to extend this to years.. Is it just yy instead of mm??
 
You should always test your deletes before you do them.

Code:
[!]Select *[/!] from vcsv_payment_stage
where time_moved < dateadd(year, -4, getdate())

If you get the data you expect, then change it to...

Code:
[!]delete[/!] from vcsv_payment_stage
where time_moved < dateadd(year, -4, getdate())

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top