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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.