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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:34:45+00:00 2026-06-06T07:34:45+00:00

Table #1: qa_returns_items Table #2: qa_returns_residues I have a long time trying to get

  • 0

Table #1: qa_returns_items enter image description here

Table #2: qa_returns_residuesenter image description here

I have a long time trying to get this Result:

item_code -   item_quantity
2         -   1
3         -   2

IF qa_returns_items.item_code = qa_returns_residues.item_code AND status_code = 11 THEN

item_quantity = qa_returns_items.item_quantity –
qa_returns_residues.item_quantity

ELSEIF qa_returns_items.item_code = qa_returns_residues.item_code AND status_code = 12 THEN

item_quantity = qa_returns_items.item_quantity +
qa_returns_residues.item_quantity

ELSE

show diferendes

END IF

I tried this Query:

select  SubQueryAlias.item_code, 
        item_quantity
from    (
        select  
                ri.item_code
        ,       case status_code
                when 11 then ri.item_quantity - rr.item_quantity 
                when 12 then ri.item_quantity + rr.item_quantity
                end as item_quantity
        from    qa_returns_residues rr
        left join    qa_returns_items ri
        on      ri.item_code = rr.item_code
        WHERE ri.returnlog_code = 1
        ) as SubQueryAlias
where   item_quantity > 0 GROUP BY (item_code);

The query returns this result:

item_code -   item_quantity
1         -   2
2         -   2
  • 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-06T07:34:47+00:00Added an answer on June 6, 2026 at 7:34 am

    I solved my problem:

    SELECT  
            item_code, 
            item_quantity, 
            item_unitprice, 
            item_subtotal, 
            item_discount, 
            item_total 
    FROM (
            SELECT  qa_returns_items.item_code, 
                    qa_returns_items.item_quantity, 
                    qa_returns_items.item_unitprice, 
                    qa_returns_items.item_subtotal, 
                    qa_returns_items.item_discount, 
                    qa_returns_items.item_total 
            FROM qa_returns_items 
            WHERE returnlog_code = 1
        UNION
            SELECT  qa_returns_residues.item_code, 
                    qa_returns_residues.item_quantity, 
                    qa_returns_residues.item_unitprice, 
                    qa_returns_residues.item_subtotal, 
                    qa_returns_residues.item_discount, 
                    qa_returns_residues.item_total 
            FROM qa_returns_residues 
            WHERE returnlog_code = 1 
            ORDER BY item_code ASC
    ) 
    AS SubQueryAlias
    WHERE item_code NOT IN (
                            SELECT a.item_code 
                            FROM qa_returns_items a 
                            JOIN qa_returns_residues b 
                                ON b.item_code = a.item_code 
                            WHERE a.returnlog_code = 1 
                                AND b.returnlog_code = 1
                            );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

table { id: long name: string } 1235 Fred 1902 Trever 5123 George 6467
I have windows service that's select some records. And it works like this: using
I am trying to update database fields from one SQL Server table to another.
I have a table on my QA Environment. I want to copy the data
So I have a table: CREATE TABLE TABLE_NAME ( COLUMN_1 char(12) NOT NULL, COLUMN_2
I have 2 tables: The question table with the following structure: id title userid
I have a table in which a field contains an integer or NULL .
i'm getting the error: Every derived table must have its own alias but i
I have a model # == Schema Information # # Table name: posts #
Table: UserId, Value, Date. I want to get the UserId, Value for the max(Date)

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.