Solved

Delete SQL records older than today

Posted on 2003-10-28
6
814 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 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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.
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 …
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
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.

626 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