Solved

Delete Data over 15 months

Posted on 2009-05-11
4
264 Views
Last Modified: 2013-11-30
Hi All,

I'm looking for a query which will delete all the data that is over 15 months old from a table called Tab A. The column which holds the time is called Data Time. The query will be schedule to run at the end of every month and it should delete the data that is over 15 months.

For ex: If the Data Time is 05/11/09, the query should delete all the rows that are over 03/11/08.

Below is the query I'm trying, I would really appreciate if y'all can provide some comments or suggestions.
DELETE FROM [TABLE A]
WHERE DATEADD (MONTH,-15,[DATA TIME])

Open in new window

0
Comment
Question by:Samoin
4 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 150 total points
ID: 24355852
DELETE FROM [TABLE A]
WHERE [DATA TIME] <  DATEADD (MONTH,-15,GetDATE() )
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 50 total points
ID: 24355874
this will be better:
DELETE FROM [TABLE A]
WHERE [DATA TIME] < DATEADD (MONTH,-15, GETDATE() )

Open in new window

0
 
LVL 6

Assisted Solution

by:bull_rider
bull_rider earned 50 total points
ID: 24355901
This would go good
DELETE FROM [TABLE A]
WHERE [DATA TIME] < DATEADD (MONTH,-15, GETDATE() )

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question