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. :)