Not sure how easy this is to do in SQL?
I've got 5 datetime fields and a RecipientID - what I need to do if possible is create a 2 Year Recency Flag based on the most recent of all these dates per Recipient.
So if any of the dates are within 2 years of today per Recipient then derive a flag/field with a Y in it
Datetime Format: 2005-11-07 08:29:57.107
Table fields:
RecipientID
FirstLogin
LastUpdatedDate
txtRegDate
dteExtExpDate
dteFreedate
Case datediff (years ,today ,datefield) <= 2
Then 'Y' end
Like this for all datefield s
Hope it helps
CASE WHEN FirstLogin >= DATEADD(YEAR, -2, CAST(GETDATE() AS date)) OR
LastUpdatedDate >= DATEADD(YEAR, -2, CAST(GETDATE() AS date)) OR
txtRegDate >= DATEADD(YEAR, -2, CAST(GETDATE() AS date)) OR
dteExtExpDate >= DATEADD(YEAR, -2, CAST(GETDATE() AS date)) OR
dteFreedate >= DATEADD(YEAR, -2, CAST(GETDATE() AS date))
THEN 'Y' ELSE 'N' END AS recency_flag
Thank you both - I'll take a look at these today