Created
April 11, 2019 12:46
-
-
Save umair-me/08eea8500a17eac919ab0d64859183bb to your computer and use it in GitHub Desktop.
Delete older records by date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--This assumes 24 hours to the minute: | |
DELETE | |
MyTableWhere | |
WHERE | |
MyColumn < DATEADD(day, -1, GETDATE()) | |
--This assumes yesterday midnight: | |
DELETE | |
MyTableWhere | |
WHERE | |
MyColumn < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -1) | |
https://stackoverflow.com/a/1588846/1158845 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment