0

How do I make 'null' data represented as 0 instead of 'null'? See query below and screenshot :)

SELECT Supervisor,
SUM(CASE WHEN DAYOFWEEK(workdate) = 2 THEN (case when employeehours.paycode = '01 Ordinary' then (employeehours.employeehours * `base rate`) end) END) `Monday`,
SUM(CASE WHEN DAYOFWEEK(workdate) = 3 THEN (case when employeehours.paycode = '01 Ordinary' then (employeehours.employeehours * `base rate`) end) END) `Tuesday`,
SUM(CASE WHEN DAYOFWEEK(workdate) = 4 THEN (case when employeehours.paycode = '01 Ordinary' then (employeehours.employeehours * `base rate`) end) END) `Wednesday`,
SUM(CASE WHEN DAYOFWEEK(workdate) = 5 THEN (case when employeehours.paycode = '01 Ordinary' then (employeehours.employeehours * `base rate`) end) END) `Thursday`,
SUM(CASE WHEN DAYOFWEEK(workdate) = 6 THEN (case when employeehours.paycode = '01 Ordinary' then (employeehours.employeehours * `base rate`) end) END) `Friday`,
SUM(CASE WHEN DAYOFWEEK(workdate) = 7 THEN (case when employeehours.paycode = '01 Ordinary' then (employeehours.employeehours * `base rate`) end) END) `Saturday`
JOIN payroll.employeehours ON employeedatanew_copy.`ID Number` = employeehours.employeeid
WHERE employeehours.workdate BETWEEN '$staticstart' AND '$staticfinish'
GROUP BY supervisor

enter image description here

5
  • 1
    Use IFNULL() function. Commented Dec 5, 2013 at 1:26
  • like so? does not work.... SUM(CASE WHEN DAYOFWEEK(workdate) = 2 THEN (CASE WHEN employeehours.paycode = '02 Overtime 1.5' then (IFNULL(IF(Other Rate = 0, (employeehours.employeehours * Base Rate),(employeehours.employeehours * Other Rate)),0)) end) END) Monday, Commented Dec 5, 2013 at 1:31
  • got it! IFNULL(SUM(CASE WHEN DAYOFWEEK(workdate) = 2 THEN (CASE WHEN employeehours.paycode = '02 Overtime 1.5' then (IF(Other Rate = 0, (employeehours.employeehours * Base Rate),(employeehours.employeehours * Other Rate))) end) END),0) Monday, Commented Dec 5, 2013 at 1:31
  • thanks heaps man, your a life saver! Commented Dec 5, 2013 at 1:32
  • Sure. COALESCE (which is a standard function) would've worked as well the same way. Commented Dec 5, 2013 at 1:34

1 Answer 1

2

Use COALESCE()

Returns the first non-NULL value in the list, or NULL if there are no non-NULL values.

COALESCE(employeehours.employeehours * `base rate`, 0)
Sign up to request clarification or add additional context in comments.

1 Comment

this is useful to me for future but not in this case, as I am looking to get rid of the nulls, thanks anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.