Results 1 to 8 of 8
  1. #1
    ManC is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    22

    Query to compare two quantities from different tables

    Hi!!
    I am stuck with a query.
    I have one table with company name, product name, and quantity (This is a list of all products that have been purchased). I have another table which also has all these fields and a few other related fields (This table stores the list of products which have been assigned to someone, in other words, they are being used).I want the user to input the company name and product name.I need to compare total quantity of the product(value passed by user) purchased for the particular company(comes from table1) and how many of the products(user input product) are in use(comes from table 2). I want all this to come from a single query.


    Is it possible?
    Please let me know if my requirement is not clear.
    Thanks.

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok....so you have Table1.CompanyName, Table1.ProductName, Table1.Quantity and Table2.CompanyName, Table2.ProductName, Table2.Quantity. You want input from the user (Where is the input coming from?). Once you get the input you want to compare Table1.Quantity and Table2.Quantity......
    i.e. I input Company1, Product1 and a quantity of 500. You want the query to say "Table1.Quantity is 250 and Table2.Quantity is 250"?

  3. #3
    ManC is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    22
    okay let me put it in real simple terms.
    I input the product name via a combobox on a form.
    I extract the total quantity of product purchased for each company from table 1.
    And i extract the total quantity of product InUse for each company from table 2.
    Now i want to compare the 2 quantities.Because the number of products purchased might be more than those 'In Use'.
    So i want to make a comparison...i want a report which might look like:
    QuantityPurchased , QuantityInUse, Difference (group by company name)

    Is it possible to get something like this?
    Thanks a lot for your help.

  4. #4
    objNoob is offline Novice
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    21
    Code:
     
    SELECT instock.company as Company, instock.productAmount as [On Hand], SUM(inuse.productAmount) as [In Use], instock.productAmount - SUM(inuse.productAmount) as [Difference]
    FROM tblPurchase as instock, tblEmployees as inuse
    WHERE instock.company = inuse.comany AND instock.productID =  inuse.productID
    GROUP BY instock.company, instock.productAmount;
    This is the idea....

  5. #5
    ManC is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    22
    This is my query:
    SELECT tbl_ConsolidatedAddItem.CompanyName, tbl_ConsolidatedAddItem.ProductName, Sum(tbl_ConsolidatedAddItem.ProductQuantity) AS productQuantity, Sum(tbl_ConsolidatedAddItem.LicenseQuantity) AS licenseQuantity, Tbl_Assignment.CompanyName, Tbl_Assignment.ProductName, Sum(Tbl_Assignment.Quantity) AS AssignedQuantity
    FROM tbl_ConsolidatedAddItem, Tbl_Assignment
    WHERE (((tbl_ConsolidatedAddItem.PurchaseStatus)="Purcha sed") AND ((Tbl_Assignment.UsageStatus)="In Use") AND ((tbl_ConsolidatedAddItem.CompanyName)=[Tbl_Assignment].[CompanyName]) AND ((tbl_ConsolidatedAddItem.ProductName)=[Tbl_Assignment].[ProductName]))
    GROUP BY tbl_ConsolidatedAddItem.CompanyName, tbl_ConsolidatedAddItem.ProductName, Tbl_Assignment.CompanyName, Tbl_Assignment.ProductName;

    I hope you can make sense out of it.
    It displays the correct sum for productquantity and licensequantity but it adds up AssignedQuantity 3 times since there are three entries for this company in 1st table...
    where am i going wrong??

  6. #6
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    I have some questions
    1) do you maintain seperate tables for company and products.
    2) If yes then do you have a product and company link table.
    3) if you don't use this structure that I have mentioned then how do you check that e.g. Product A from Company X is Issued But actually Product A is Bought From Company Y.
    4) Are Company in Both the tables refer to the company from which the product is purchased or In product IN table represents the Company from which the product is Purchased and in Product is Company to whom the Product is being sold. (I assume they are the same)

    Remember the most important thing about a databes is its table structure if it is sound then its very simple.

  7. #7
    ManC is offline Novice
    Windows 7 Access 2007
    Join Date
    Mar 2010
    Posts
    22
    I'll tell you what my application does then maybe you can suggest me some changes.
    My company usually does purchasing for its sister concerns. So i need to develop an application to record all this info.
    There is one table to store which product was bought for which company. Say a router was bought FOR company X. So this table includes fields invoice number, invoice date,companyname(for which the product is purchased),vendor,productname,productquantity,prod description,purchasestatus(could be purchased/not purchased/transferred),unitprice,licensekeylist,licensequant ity,comments....
    Now when a product from the above table is used, there is an entry to me made in another table called tbl_Assignment which stores info as to whom was the product(say router) was assigned to.This table includes fields Companyname(which company does the assignee belongs to),assignedto (the assignee),vendor, product name(its a combo box which is filled from the 1st table), productdescription,licensekey,usagestatus,quantity ,comments.
    Now it is possible that a company can start using a product without buying it.So i need a report which states the total quantity of a particular product(say, routers) purchased for a company X[comes from the 1st table] ,and the total quantity of routers assigned(or InUse) by company X [comes from the 2nd table]....
    please let me know if all this makes no sense ...
    I am kinda stuck on this for quite sometime now...
    thanks.

  8. #8
    DenverGuy is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Jan 2014
    Posts
    1

    Same Problem, help!

    Ever find your answer to this? this is my exact problem too

    Quote Originally Posted by ManC View Post
    This is my query:
    SELECT tbl_ConsolidatedAddItem.CompanyName, tbl_ConsolidatedAddItem.ProductName, Sum(tbl_ConsolidatedAddItem.ProductQuantity) AS productQuantity, Sum(tbl_ConsolidatedAddItem.LicenseQuantity) AS licenseQuantity, Tbl_Assignment.CompanyName, Tbl_Assignment.ProductName, Sum(Tbl_Assignment.Quantity) AS AssignedQuantity
    FROM tbl_ConsolidatedAddItem, Tbl_Assignment
    WHERE (((tbl_ConsolidatedAddItem.PurchaseStatus)="Purcha sed") AND ((Tbl_Assignment.UsageStatus)="In Use") AND ((tbl_ConsolidatedAddItem.CompanyName)=[Tbl_Assignment].[CompanyName]) AND ((tbl_ConsolidatedAddItem.ProductName)=[Tbl_Assignment].[ProductName]))
    GROUP BY tbl_ConsolidatedAddItem.CompanyName, tbl_ConsolidatedAddItem.ProductName, Tbl_Assignment.CompanyName, Tbl_Assignment.ProductName;

    I hope you can make sense out of it.
    It displays the correct sum for productquantity and licensequantity but it adds up AssignedQuantity 3 times since there are three entries for this company in 1st table...
    where am i going wrong??

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 02-03-2010, 09:17 PM
  2. Adding Quantities?
    By prosbloom225 in forum Reports
    Replies: 0
    Last Post: 09-02-2009, 01:25 PM
  3. Compare date in a sql query
    By access in forum Forms
    Replies: 2
    Last Post: 06-17-2009, 12:57 PM
  4. Comparing Part Quantities According to Dates
    By rochy81 in forum Reports
    Replies: 6
    Last Post: 05-19-2009, 09:11 AM
  5. organizing serial numbers and quantities
    By Diomeneus in forum Access
    Replies: 0
    Last Post: 11-14-2008, 03:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums