Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Select records older than 30 days (SOLUTION)

records

  • Please log in to reply
No replies to this topic

#1 cdg10620

cdg10620

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 344 posts
  • Programming Language:C#, JavaScript, PL/SQL, Transact-SQL, VBScript, Others

Posted 30 March 2010 - 09:42 AM

I recently had an issue where I wanted to retrieve all of the records in a table that were over 30 days old. I have an snmp monitor that logs server temperatures and stores them in the database. I want to take all of the records that are older than 30 days and "clean out" the old records so that the database doesn't end up being huge. In the table there is a column called "RetrievalTime." I used that column and in the query only returned records where the retrieval time was older than 30 days. Here's the query:

SELECT * FROM Table_Name
WHERE RetrievalTime <= GETDATE() - DAY(30)

If you only want to return items within the past 30 days you can write it like this:\


SELECT * FROM Table_Name
WHERE RetrievalTime >= GETDATE() - DAY(30)

Hope someone finds this helpful. :)
  • 0
-CDG10620
Software Developer





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download