knamc
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
DATEDIFF ( datepart , startdate , enddate )
http://msdn.microsoft.com/en-us/library/ms189794(v=sql.105).aspx