Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8489091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:43:45+00:00 2026-06-10T21:43:45+00:00

When i run this query: select (IFNULL(ROUND(convertUnits(‘40892′,SUM(o.qty),o.pricingUnit,’FT’)),0)) as oItemQty, (SELECT IFNULL(sum(i.qty),0) from inventory i

  • 0

When i run this query:

select 
(IFNULL(ROUND(convertUnits('40892',SUM(o.qty),o.pricingUnit,'FT')),0)) as oItemQty,
(SELECT IFNULL(sum(i.qty),0) from inventory i where i.partID='40892' and i.type=16 and        i.refDocNum=w.woID and i.refApp='WO') as iItemQty,
(IFNULL(ROUND(convertUnits('40892',SUM(o.qty),o.pricingUnit,'FT')),0) - (SELECT    IFNULL(sum(i.qty),0) from inventory i where i.partID='40892' and i.type=16 and    i.refDocNum=w.woID and i.refApp='WO')) as sum
from orderitem o left join wo w on o.orderitemID=w.orderitemID 
where o.partID='40892' and
w.status not in (1,5) and 
(SELECT cancelDate from orders where orders.orderID=o.orderID)='0000-00-00' and 
o.createWO=1 and 
(SELECT orderDate from orders where orders.orderID=o.orderID) >='2012-07-01'

i get 13650 for “oItemQty” and 2730 for “iItemQty”. The problem i’m having is the field “sum” should be oItemQty – iItemQty (10920). Right now it is returning 13650 (oItemQty).

What am i missing here? Why when i run the subqueries as separate fields are the numbers correct but when i try to subtract it doesn’t work properly?

Update: Turns out it was a casting issue. Once i casted the iItemQty as unsigned it subtracted properly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:43:47+00:00Added an answer on June 10, 2026 at 9:43 pm

    Looking at your query, the first problem I notice is that you are negating your left join by including this in the WHERE clause:

    w.status not in (1,5)
    

    You should move that into the ON clause of the left join to preserver the intent of that join. As it is now that is essentially being treated as an inner join.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: oracle PL/SQL: sort rows I run this query: Select a.product, sum( case
When I run this query: select First_Name, sum(a) a, sum(b) b, sum(c) c from
If I run this query in Toad: SELECT BANDID, BANDNAME FROM WOODSTOCK WHERE BANDNAME
If I try to run this query in SQL Server 2005: SELECT 1 WHERE
i am trying to run a query like this SELECT a, b , c,
I'm trying to run this query: SELECT COUNT(events.event_id) AS total_events, COUNT(matches.fight_id) AS total_matches, COUNT(players.fighter_id)
If I run this query: SELECT `Manga`.`id`, `Manga`.`name` FROM `mangas` AS `Manga` WHERE `Manga`.`id`
When I run this query: SELECT m.tag_id, m.product_id, count(m.product_id) as dups FROM product_tag_map m
If I run a query like this: insert into table (unique_id, column) select (isnull(max(cast(unique_id
I'm trying to run this query: SELECT Destaque.destaque, Noticia.id, Noticia.antetitulo, Noticia.titulo, Noticia.lead, Noticia.legenda, Noticia.publicacao,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.