Jump to content

Select records older than 30 days (SOLUTION)

- - - - -

  • Please log in to reply
No replies to this topic

#1
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
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. :)
-CDG10620
Software Developer




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users