I am trying to write a SQL the will pull up either all date ranges or those past 90 days. Everything work but the following code where the code desided what date to look at.
WHERE
CASE @All_90
WHEN @All_90 = 1
THEN td.DateSeen NOT BETWEEN DATEADD(day,-90,GETDATE()) and GETDATE()
@All_90 is the variable to determine if the code will look at all dates or just those not before 90 days.
I think this will do it for you: