Jump to content

Help with selects and null


xander85

Recommended Posts

Hi All,

 

I am trying to sum three subselects and return a single value; however, if any of the three returns AS null then the value is NULL. How can I change my statement so if any are null they simply add as 0?

 

Here is my code (the id, site_id, and workid numbers are simply for reference)

 

select 
(sum(work_orders.unitprice * work_orders.qty) + 
(SELECT sum((expenses.markup * expenses.total)*expenses.qty) from expenses where expenses.id = 15 AND expenses.workid = 3 AND expenses.site_id = 5) + 
(select SUM(dist*.485) from mileage where id = 15 and site_id = 5 and workid = 3 AND billed = 1 GROUP BY id AND site_id AND workid)) as total
from work_orders 
where work_orders.id = 15 and work_orders.site_id = 5 and work_orders.workid = 3 
GROUP BY work_orders.id AND work_orders.site_id AND work_orders.workid

Link to comment
https://forums.phpfreaks.com/topic/91447-help-with-selects-and-null/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.