Solved

Delete Data over 15 months

Posted on 2009-05-11
4
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

705 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