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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:30:48+00:00 2026-06-15T17:30:48+00:00

I am searching Invoice Itemized Table for Invoices with Quantity having >0 and <0.

  • 0

I am searching Invoice Itemized Table for Invoices with Quantity having >0 and <0. Invoice Itemized table contains details of all the items in an Invoice. How can I write a query that gives all the invoices that have Quantity of items >0 and <0.

  • 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-15T17:30:49+00:00Added an answer on June 15, 2026 at 5:30 pm

    How about something like this? This uses two queries. The first finds all the invoices with Negative Quantities. Then it APPLY’s the second query to find from that list of invoices only those that also have positive quantities.

    SELECT DISTINCT
      PosNegInvoices.InvoiceID 
    FROM ItemizedInvoice AS NegInvoices
    CROSS APPLY
    (
      SELECT
        InvoiceID
      FROM ItemizedInvoice 
      WHERE InvoiceID = NegInvoices.InvoiceID
      AND Quantity > 0
    ) AS PosNegInvoices
    WHERE NegInvoices.Quantity < 0
    

    Here is another version that uses CTEs:

    WITH NegInvoices AS
    (
      SELECT
        InvoiceID
      FROM ItemizedInvoice
      WHERE Quantity < 0
    ),
    PosInvoices AS 
    (
      SELECT
        InvoiceID
      FROM ItemizedInvoice
      WHERE Quantity > 0
    )
    SELECT DISTINCT
      PosInvoices.InvoiceID
    FROM NegInvoices 
    JOIN PosInvoices
    ON NegInvoices.InvoiceID = PosInvoices.InvoiceID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I searching to get all contents that are tagged with some Tags. $OR can't
Searching for values that uses the same value Example SELECT Name, UnitPrice, Quantity, Color
Searching online, I found a method I needed that can merge arrays. It was
I have an invoices table which stores a single record for each invoice, with
I´m searching some providers or frameworks or something that can deliver a map like
Searching here I found that this question was already asked , but I think
Searching open source projects , shows me that spec files in the wild do
Searching for a script, which can do show/hide functions without framework. Something like: <span
Searching SO and Google, I've found that there are a few Java HTML parsers
I have a zip file named test.zip which contains a directory named invoice. Inside

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.