Hello All!
I have a table with a date column. I would like to be able to DELETE the rows based on the date column. The condition is 30 days from todays date. So anything older than 30 days from todays date, it will delete those rows.
Any suggesttion the best way to do this. I was thinking of a simple select statement, but can't figure it out.
TIA!!
Rudy
Hi there,Is your date column of data type DateTime? If so, try something like:
DELETE FROM [Table Name]
WHERE DATEADD(d, -30, GETDATE()) > [Date Column]
What happens is DATEADD(d, -30, GETDATE()) is used to obtain a date that is 30 days from todays date. Then, anything in the table where the entry in the Date Column (which I assume is of data type DateTime) is older than DATEADD(d, -30, GETDATE()), i.e. older than 30 days from today's date, gets deleted.
Hope that helps a bit, but sorry if it doesn't.
|||Thank you! Just what I needed!
No comments:
Post a Comment