Page 2 of 3 FirstFirst 123 LastLast
Results 16 to 30 of 31
  1. #16
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862

    Refer to post #9. You need a working query.

  2. #17
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    oh okay.

    Is it possible to divide a field in a table by a field in a query using another query?

  3. #18
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Yes but, the calculation is done in the second query first. Then, the main query will retrieve the calculated data, avoiding the ambiguous join error.

  4. #19
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    ah okay!

    sorry i mistook what you meant by working query. I have a working query, this is it:
    Code:
    SELECT SUPPLIERS.[SUPPLIER NAME], Sum(ORDERS.QUANTITY) AS [DEFECTIVE PARTS]FROM (ORDERS INNER JOIN PARTS ON (PARTS.[PART NUMBER] = ORDERS.[PART NUMBER]) AND (ORDERS.[PART NUMBER] = PARTS.[PART NUMBER])) INNER JOIN SUPPLIERS ON PARTS.ID = SUPPLIERS.ID
    WHERE (((ORDERS.[ORDER CODE])=2))
    GROUP BY SUPPLIERS.[SUPPLIER NAME];

  5. #20
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    So you want to multiply the Sum(ORDERS.QUANTITY) by 100 and then divide that by ORDERS.QUANTITY ? What is the expression you tried using with this SQL? How does your question in post #1 realate to this SQL?

  6. #21
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    that is my query used to calculate how many defective parts were sold by each supplier.

    I want to divide that by the total sold by each supplier (which is the quantity in the orders table) and then multiple the answer by 100

  7. #22
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If the SQL in post #19 is provideing good results then build another query to manage the rest of the calcualtion. In the second query add the necessary tables and also add the first query. When you create your alias in your new second query, you will need to include the query name that created the alias DEFECTIVE PARTS.

    MyCalc: (([QueryName].[defective parts]/[TableName].[quantity]) * 100)

    This is assuming quantity is a field in a table and said table is on your new query. If you are still having troubles, uploaded your last atempt here by removing personal data, compact and repair, and Zip Down the file.

  8. #23
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    my file is 544kb after clicking on compact and repair

  9. #24
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    i tried it but it keeps showing up with the sql error

  10. #25
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    can i send a bigger file through private message on the forum?

  11. #26
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    What if you "Send To" and "Zipped" using the mouse's Right Click?

  12. #27
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    ah okay i done itAttachment 15862

  13. #28
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    ....zip

    there

  14. #29
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Unfortunately, your tables are not "Normalized". You should have relationships between your tables based on Primary Key fields and Foreign Key fields.

    For instance, the relationship between table Parts and table Suppliers will not work. You can not JOIN two tables together on their Primary Key Fields. Your parts table has a field named, "Supplier". This field is text. It does not make sense to store the literal text of the Supplier in this field. It would make more sense to Use the "Supplier" field as a Foreign Key to the Primary Key in the Supplier table. The Supplier field would then be a Long Integer data type to accommodate the Autonumber field that is the Primary Key in table Suppliers.

    You store the Primary Key value in the corresponding Foreign Key field. The data types need to match. AutoNumber fields fit into Long Integer data types. You would base your relationship on these PK/FK fields. You use these relationships to create JOINS in your queries.
    You should study up on the term, Relational Data Base Management System (RDBMS). RDBMS rely on a Normalized table structure, or Relations. Without this you will not be able to build a query. Without queries you will not be able to build a public interface or be able to Manage your data. This needs to come first.
    Use Autonumber fields where possible to generate PK’s

    Use Foreign Key fields in relative tables to store the PK value in the FK field, thus allowing a relationship.

    Do not create relationships based on text. Use whole number data types like long integers.

    Do not use special characters, spaces, or reserved words in the names of your objects ie, tables, reports, forms, etc.

  15. #30
    rp123 is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2014
    Posts
    18
    oh okay. thank you very much for your help! should I start a new database or edit the relationships in the current one?

Page 2 of 3 FirstFirst 123 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. 2nd column in cross table query
    By khartoum in forum Queries
    Replies: 7
    Last Post: 07-04-2012, 12:40 PM
  2. Divide a column by another Column in a Report?
    By taimysho0 in forum Reports
    Replies: 2
    Last Post: 01-06-2012, 06:25 PM
  3. Replies: 1
    Last Post: 12-16-2011, 08:16 AM
  4. Replies: 0
    Last Post: 03-18-2010, 01:31 PM
  5. Replies: 1
    Last Post: 04-09-2009, 09:18 AM

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