Solved

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

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error message when scheduling a job using a linked Server 12 60
SQL Merige returns error code when updating 15 52
Need help with a query 6 72
sql query help 2 51
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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

808 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