Solved

Delete SQL records older than today

Posted on 2003-10-28
6
807 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
  • 4
6 Comments
 
LVL 8

Accepted Solution

by:
Dishan Fernando earned 250 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
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 to return specific rows and columns, with various degrees of sorting and limits in place.

828 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