?
Solved

Delete Data over 15 months

Posted on 2009-05-11
4
Medium Priority
?
267 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 450 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 150 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 150 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

Industry Leaders: 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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Suggested Courses

765 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