SQLTeam.com | Weblogs | Forums

SQL Statement for the last 2 years


#1

I am trying to figure out how to take field called Board Approved Date to see if it is in within the last 3 years

Example Board Approved date field is 08/29/2016, is this within the last 3 years of 1/31/2015? The result should say "Y"


#2

I don't understand this part within the last 3 years of 1/31/2015
Any how here something :

 CASE WHEN DATEADD(YEAR,-3,GETDATE())< [Board Approved Date] 
	AND [Board Approved Date]  < GETDATE() THEN 'Y' 
    ELSE 'N' 
 END as result

where
DATEADD(YEAR,-3,GETDATE()) will return 01/12/2014 18:46:14 = last 3 year from present.
If you want from 1/31/2015 , you can replace GETDATE with your value