mysql - Using CASE Function with DATEDIFF and COUNT -
hi i'm sure simple fix cannot figure out. i'm trying label records overdue completion date (completedate-currentdate) (these numbers negatives) "overdue" report. records not altered numbers not negatives. here snippet of code giving me null entries
select case datediff(targetcompletedate, now()) when count(*) <=0 'overdue' end 'days left',
any appreciated thanks
there 2 variants of case
:
case when condition1 result1 when condition2 result2 ... else result_else end
case scalar_expression when value1 result1 when value2 result2 ... else result_else end
in case, should first syntax, because not comparing specific values range. instead, query using second syntax. count(*)<=0
expression evaluated boolean implicitly converted integer, type implied datediff
result.
you need use first syntax, this:
select case when targetcompletedate null 'not set' when datediff(targetcompletedate, now()) <= 0 'overdue' else datediff(targetcompletedate, now()) end 'days left'
Comments
Post a Comment