Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Delete SQL records older than today

Posted on 2003-10-28
6
Medium Priority
?
820 Views
Last Modified: 2012-05-04
I have a SQL table where I need to delete records. I need to delete all the records accept todays records. The table have around 800,000 records. The table has the following fields.
ID, Curr, Bid, LastUpdate, Offer.

The LastUpdate field is the one with the dates which is in this format 28 Oct 2003 10:52

How will I go about to delete the records older than today.
0
Comment
Question by:SilverMecer
[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
  • 4
6 Comments
 
LVL 8

Accepted Solution

by:
Dishan Fernando earned 1000 total points
ID: 9632820
try this...

DELETE
FROM <TableName>
WHERE LastUpdate < GETDATE()

OR

WHERE LastUpdate < '28-10-2003'
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 9632925
can you do the following instead

select * into #temp
where lastupdate < getdate()

truncate tablename

insert into tablename
select * from #temp


but how frequenctly do you need to do this?
you should ensure you have a full database backup before hand of the database
you'll also need to take a full database backup after the insert completes.


 
0
 

Author Comment

by:SilverMecer
ID: 9632928
I got the following error

The convertion of a char data type to a datetime data type resulted in an ou-of-range datetime value
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:SilverMecer
ID: 9632934
We need to this at least once a month because the table get updated every 5 min for 24 hours a day. This a Rate server for currency convertion
0
 

Author Comment

by:SilverMecer
ID: 9633010
I have used the following string to do the deletion thank you for all your help.

DELETE FROM Rates
WHERE (LastUpdate < CONVERT(DATETIME, '2003-09-28 00:00:00', 102))
0
 

Author Comment

by:SilverMecer
ID: 9633094
Can one automate this process
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

670 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