Solved

I need a simple script to delete data older than 6 months.

Posted on 2008-06-10
2
650 Views
Last Modified: 2010-04-21
Hello, I have a simple data table with "Key Sequence, name, devicename, originstation, winlogin_name, date, and messageinfo" columns.  

The date column is in DateTime format (MM/DD/YYYY HH:MM:SSAM).
I can remove records older than a specific date range manually but I am trying to write a simple script that when run will "Delete records older than 6 months."  Nothing fancy, just simple purge from the table.

I have tried several ideas from the Experts exchange but they all return errors.  Is there a simple no frills general command line that would specify "older than 6 months"?
Thanks,
Brian
0
Comment
Question by:KollBrian
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 21750617
no problem:
SELECT * FROM yourtable WHERE [date] < dateadd(month, -6, getdate()) 
and to delete
DELETE yourtable WHERE [date] < dateadd(month, -6, getdate())

Open in new window

0
 

Author Closing Comment

by:KollBrian
ID: 31465706
Wow, fast and easy, thank you very very much. :)  
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 208R2 not recognizing DBF file in linked Server 11 60
How to query LOCK_ESCALATION 4 41
Caste datetime 2 64
SQL query with cast 38 53
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…

861 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