Link to home
Start Free TrialLog in
Avatar of knamc
knamcFlag for United States of America

asked on

DATEDIFF problem

Hi,  I am trying to write a case statement were I am comparing to dates to determine the result.  I do not think I am using the datediff function correctly.  I am hoping someone can take a look at my code and offer suggestions.

select
case
          when
            DATEDIFF(day, reportdate) - DATEDIFF(day,[Expected Close Date]) <=182)
            then '6 months'
          when DATEDIFF(day, reportdate) - DATEDIFF(day,[Expected Close Date])<=365)
          then '12 months
          else 'Rest'
        end as timeframe
from dbo.wkly_report
ASKER CERTIFIED SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the grade.  Good luck with your project.  -Jim
>>I do not think I am using the datediff function correctly
DATEDIFF ( datepart , startdate , enddate )

http://msdn.microsoft.com/en-us/library/ms189794(v=sql.105).aspx