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 9123107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:15:33+00:00 2026-06-17T06:15:33+00:00

So I have the below code SELECT PICK_SO_NUMBER, CUSTOMER, SO_PRODUCT, DO_QUANTITY, DO_PACKING, DO_DATE, COALESCE(INVOICED_QTY,

  • 0

So I have the below code

SELECT PICK_SO_NUMBER, CUSTOMER, SO_PRODUCT, DO_QUANTITY, DO_PACKING, DO_DATE,
COALESCE(INVOICED_QTY, 0) AS INVOICED_QTY, 
DO_QUANTITY-INVOICED_QTY AS NOT_INVOICED, 
INVOICE_PACKING 
FROM VW_TRAFFIC_PO_SIDE
WHERE  DO_QUANTITY > INVOICED_QTY OR (INVOICED_QTY IS NULL AND DO_QUANTITY IS NOT NULL)

The line below the coalesce, is suppose to subtract the DO_QUANTITY from INVOICED_QTY, however when INVOICED_QTY is NULL, it no longer subtracts by 0, it subtracts by null, and thus the new column returns nulls where INVOICED_QTY is null

I tried multiple things: tried coalesce to a case, writing the coalesce as INVOICED and then using INVOICED in the subtraction expression, I tried using the coalesce in the same line as the subtraction (without comma in between, I felt this was the solution that would work best, but couldn’t get it to compile)

  • 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-17T06:15:34+00:00Added an answer on June 17, 2026 at 6:15 am

    It gets confusing when you use the same alias ‘invoiced_qty’ in the select-list and in the WHERE clause. The value in the subtraction is the raw column value, not the coalesced value from the previous select-list item. The same is true in the WHERE clause.

    SELECT PICK_SO_NUMBER, CUSTOMER, SO_PRODUCT, DO_QUANTITY, DO_PACKING, DO_DATE,
           COALESCE(INVOICED_QTY, 0) AS INVOICED_QTY, 
           DO_QUANTITY - COALESCE(INVOICED_QTY, 0) AS NOT_INVOICED, 
           INVOICE_PACKING 
      FROM VW_TRAFFIC_PO_SIDE
     WHERE DO_QUANTITY > INVOICED_QTY
        OR (INVOICED_QTY IS NULL AND DO_QUANTITY IS NOT NULL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the code below: string SQL = select * from + TableName; using
I have the below Code SELECT * FROM table WHERE MATCH(message) AGAINST ('Hello*') If
I have used below code for checking lastname(case sensitive) from DB. SELECT * FROM
I have below SQL statment INSERT INTO my_counts (type,code,count) SELECT type,id ,1 from my_data
I have the following SQL: select code, distance from places; The output is below:
I have the following SQL: select code, distance from places; The output is below:
I have below code working as desired but the on select works only from
I have code below: <select id=testSelect> <option value=1>One</option> <option value=2>Two</option> </select> <asp:Button ID=btnTest runat=server
Below are the options that I have in my HTML code: <label id="subn"> <select
i have below code snippet in jsp <HTML> <BODY> <select id=customerIds onchange=doOperation()> <option value=default>

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.