Solved

SQL Syntax for VB Script page

Posted on 2013-06-07
5
359 Views
Last Modified: 2013-06-07
I would like to keep records in my database for only 3 months. When users submit a new record, I'd also like records older than 3 months get deleted. This is my delete SQL with the hard coded date. What is the correct syntax if I want to replace the hard coded date, i.e. deduct 90 days from the current date?

DELETE FROM TimeTable where SubmissionDate <='2013-03-07'

Thank you for your help
0
Comment
Question by:romsom
5 Comments
 
LVL 20

Expert Comment

by:dsacker
Comment Utility
DELETE FROM TimeTable
WHERE SubmissionDate <= DATEADD(m, -3, GETDATE())
0
 
LVL 25

Assisted Solution

by:Shaun Kline
Shaun Kline earned 150 total points
Comment Utility
For SQL Server, the syntax is:

DELETE FROM TimeTable WHERE SubmittionDate <= DATEADD(m, -3, GETDATE())
0
 
LVL 20

Assisted Solution

by:dsacker
dsacker earned 150 total points
Comment Utility
Do you need to archive that data before you delete it? If so, you can INSERT INTO YourArchiveTable using the same WHERE criteria, beforehand.
0
 
LVL 25

Accepted Solution

by:
Lee Savidge earned 200 total points
Comment Utility
DELETE FROM TimeTable WHERE SubmissionDate < getdate() - 90

Do beware though that this will take into account the time element. To get around that:

DELETE FROM TimeTable WHERE SubmissionDate < cast(convert(nvarchar(10), getdate(), 103) as datetime) - 90
0
 

Author Closing Comment

by:romsom
Comment Utility
Thank you very much all of you.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now