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:

  1. case   when condition1 result1   when condition2 result2   ...   else result_else end 
  2. 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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -