Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2008-06-10
2
Medium Priority
?
896 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 1000 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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