Results 1 to 2 of 2
  1. #1
    CRAMSEY13 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2016
    Posts
    1

    Question Query design question (counts, sum, and other fun stuff)

    For my employer, I have a project to import two different reports into two different tables. Then, there is a general sales code table that contains a list of sales codes. Each sales code represents a branch of the armed forces and other trading partners of the government. The first report that is imported into tbl137Report. This table has field names of SponsorNumber (this identifies who the "customer" is), Dept, Appr, Subhead, and the accounts receivable total for the sponsor. The second report will be imported into tbl865Report, and the data fields will contain SponsorNumber, BillNumber, BillDate, Amount.

    Query 1
    SponsorNumber BillCount (This would be a count of the number of bills for each SponsorNumber...for example, in tbl865Report discussed above it may have three bills for three different amounts...let me put an example of that table and then the results that I need from the query.

    tbl865Report
    SponsorNumber BillNumber BillDate BillAmount
    SponsorA BillA 12/30/16 150.00
    SponsorA. BillB. 12/30/16. 200.00


    SponsorA. BillC. 12/30/16. 100.00

    Desired Output after query
    SponsorNumber. BillCount. Amount
    SponsorA 3. 450.00


    Query 2
    I need to somehow update tbl137Report with the information in Query 1.

    Add a table column for the BillCount from Query 1 and update the amount column with the amount from our Query that consolidated the data.

    How would I accomplish this? I have basic familiarity with using modules, so it anybody has code I can put in there it would work.

    I would like my final result to be something like
    SponsorNumber Department Appropriation Subhead BillCount from Query1 Amount updated to reflect the amount in Query 1. I hope this makes sense. I am really struggling with this work project.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Query1
    Code:
    SELECT tbl865Report.SponsorNumber, Count(tbl865Report.BillNumber) AS CountOfBillNumber, Sum(tbl865Report.BillAmount) AS SumOfBillAmount
    FROM tbl865Report
    GROUP BY tbl865Report.SponsorNumber;

    Query2
    Code:
    INSERT INTO tbl137Report ( SponsorNumber, BillNumber, BillDate, BillAmount )
    SELECT Query1.SponsorNumber, Query1.CountOfBillNumber, Query1.BillDate, Query1.SumOfBillAmount
    FROM Query1;
    What happens if there is a 4TH entry in tbl865Report with a different date?

    SponsorNumber BillNumber BillDate BillAmount
    SponsorA BillA 12/30/16 150.00
    SponsorA BillB 12/30/16 200.00
    SponsorA BillC 12/30/16 100.00
    SponsorA
    BillD
    12/31/16 175.00

    Does the bill count become 4 and the total becomes 625.00?
    Attached Files Attached Files

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

Similar Threads

  1. Linked Tables and Query Design Question
    By burrina in forum Database Design
    Replies: 4
    Last Post: 01-06-2013, 01:04 AM
  2. Query - Counts
    By maxx102 in forum Access
    Replies: 1
    Last Post: 12-14-2012, 12:49 PM
  3. Basic query design question
    By megabrown in forum Queries
    Replies: 1
    Last Post: 12-15-2010, 09:10 AM
  4. Query Design Question
    By copegjc15 in forum Queries
    Replies: 7
    Last Post: 11-13-2010, 10:28 PM
  5. Replies: 2
    Last Post: 05-27-2009, 08:47 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