Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

DATEADD and variables in SQL

To make the T-SQL  function DATEADD more dynamic use variables. The example below , accepts an input parameter , in this case “4”.

All events older than 4 months from now will be deleted.


DECLARE @months int
SET @months = 4

DELETE FROM [Events] WHERE [EventDate] < DATEADD (month,-1*@months, getdate())  


Author: Jack Vamvas (


Leave a comment on the original post [, opens in a new window]

Loading comments...