Solved

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

Posted on 2008-06-10
2
690 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
[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
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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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