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
 Stored Procedure To delete data which is 2 yrs old

Author  Topic 

hussainzim
Starting Member

21 Posts

Posted - 2007-09-24 : 20:12:52

Table Strucure - :
TestEven(TestNo,EmpNo,TestDate)


I jst want to write a stored procedure to delete all data which is 2 years old. thank you in adavance.
Hussain

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-09-24 : 20:23:44
DELETE FROM TestEven WHERE TestDate <= DATEADD(y, -2, GETDATE())

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-09-24 : 21:26:46
Do a SELECT before the DELETE for the same condition and check how many records get deleted. IF its into hundreds of thousands of rows you might want to batch it.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

hussainzim
Starting Member

21 Posts

Posted - 2007-09-25 : 04:06:05
thanks....
Go to Top of Page
   

- Advertisement -