Solved

Delete SQL records older than today

Posted on 2003-10-28
6
804 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:
dishanf 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
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.

 

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

914 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

21 Experts available now in Live!

Get 1:1 Help Now