This will return all old campaigns:
SELECT * FROM mytable WHERE campaign_Date <= DATEADD(day, -90, GETDATE())
This will result in selection 1 if the campaign is out of date, 0 otherwise:
SELECT CASE WHEN campaign_Date <= DATEADD(day, -90, GETDATE()) THEN 1 ELSE 0 END FROM mytable
Note that the first query condition is valid: it allows you to use an index to filter dates.
This will update all old campaigns with status 6 :
UPDATE mytable SET campaign_status = 6 WHERE campaign_Date <= DATEADD(day, -90, GETDATE())
Quassnoi
source share