Solved

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

Posted on 2008-06-10
2
616 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 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
Comment Utility
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
Comment Utility
Wow, fast and easy, thank you very very much. :)  
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 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

9 Experts available now in Live!

Get 1:1 Help Now