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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:23:09+00:00 2026-05-28T06:23:09+00:00

I have a table (Inventory_Line) where LID is auto increment and IID is a

  • 0

I have a table (Inventory_Line) where LID is auto increment and IID is a single number referring to the inventory date, PID is a numeric part#. We use this table for inventory.

LID  IID  NAME    PID  QTY
---  ---  ------  ---  ---
1    1    Part A  213  12
2    1    Part B  200  15
3    2    Part A  213  9
4    2    Part B  200  7

We also have a table Order_Line

OLID  OID  NAME    PID  QTY
----  ---  ------  ---  ---
1     217  Part A  213  12
2     217  Part B  200  15
3     218  Part A  213  9
4     218  Part B  200  7

My goal is to show

((Previous Inventory Qty (Inventory_Line.IID=1)) AS PREV_INV + 
(ORDERED Qty (Order_Line.OID = 217 AND 218)) AS ORDERED - 
(Current Inventory Qty Inventory_Line.IID=2) AS CURRENT_INV) AS SOLD 
WHERE PID = X

The output would be like this:

PID  NAME    PREV_INV  ORDERED  CURRENT_INV  SOLD
---  ------  --------  -------  -----------  ----
213  Part A  12        21       9            24

We are using MS Access and I have some experience with Joins but I am kind of stuck on how to pull this off. Any help would be appreciated.

  • 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-05-28T06:23:10+00:00Added an answer on May 28, 2026 at 6:23 am

    Are you thinking of something on these lines?

    SELECT t.pid,
           Nz([pi].[qty], 0) + Nz([o].[qty], 0) - Nz([s].[qty], 0) AS dat
    FROM   (((SELECT DISTINCT pid
             FROM   inventory_line) AS t
             LEFT JOIN (SELECT *
                        FROM   inventory_line
                        WHERE  iid = 2) AS pi
               ON t.pid = pi.pid)
            LEFT JOIN (SELECT *
                       FROM   inventory_line
                       WHERE  iid = 3) AS s
              ON t.pid = s.pid)
           LEFT JOIN (SELECT *
                      FROM   order_line
                      WHERE  oid = 217
                              OR oid = 218) AS o
             ON t.pid = o.pid
    WHERE  (( ( t.pid ) = [Enter:] ))
    

    The above needs some work, but what should be done would be clearer with more input on the desired output.


    Re comments

    SELECT t.pid,
           t.name,
           pi.qty,
           o.q,
           s.qty,
           Nz([pi].[qty]) + Nz([o].[q]) - Nz([s].[Qty]) AS sold
    FROM   (((SELECT DISTINCT pid,
                             [Name]
             FROM   inventory_line) AS t
             LEFT JOIN (SELECT pid,
                               qty
                        FROM   inventory_line
                        WHERE  iid = 1) AS pi
               ON t.pid = pi.pid)
            LEFT JOIN (SELECT pid,
                              qty
                       FROM   inventory_line
                       WHERE  iid = 2) AS s
              ON t.pid = s.pid)
           LEFT JOIN (SELECT pid,
                             SUM(qty) AS q
                      FROM   order_line
                      WHERE  oid = 217
                              OR oid = 218
                      GROUP  BY pid) AS o
             ON t.pid = o.pid
    WHERE  (( ( t.pid ) = [Enter:] ))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table with a unique auto-incremental primary key. Over time, entries may be
I have table in data base name train delay, with columns train number(int), DelayTime(int),
In our inventory database (SQL Server 2008 std edition) we have a table (called
I have a table that logs inventory updates throughout the day. Table InventoryHistory: UpdateID
I've got an inventory table that needs to have certain in each row, and
I have a table with inventory records and another table with documents describing each
I have a INVENTORY table. There are many items inside. When I query it,
I have a database which has an orders table and inventory table. The order-items
I have a table called Inventory with the fields Item (varchar), Amount (int), Type
we have two related tables(inventory and inventoryLocalization) on Sql Server 2005. the first table's

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.