Blog Post

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 (http://www.sqlserver-dba.com)


Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating