Results 1 to 7 of 7
  1. #1
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134

    Putting a query into another query... trivial right?

    Hi there,

    I have these two queries:

    Main query: "qryProdSize"


    Code:
    SELECT tblReportProduct.ReportID, tblReport.ActionDate, tblReportProduct.ProdSizeFROM tblReport INNER JOIN tblReportProduct ON tblReport.ReportID = tblReportProduct.ReportID
    WHERE (((tblReport.ActionDate) Between [Date1] And [Date2]));
    and Subquery: qryProdTotalSize
    Code:
    SELECT qryProdSize.ProdSize, Count(qryProdSize.ProdSize) AS CountOfProdSize
    FROM qryProdSize
    GROUP BY qryProdSize.ProdSize;

    Do I just need the replace the word "qryProdSize" for the whole main query everytime?


    Regards!

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Not sure what you are asking - "every time" what?

    This can be done in one query.

  3. #3
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    I just want the query to give me the count of the products by product category in a specific period of time.

    The first query (main query) gather all the values from the reports between the dates i specified.... but since some reports have same date, they appear several time, since the reportid is also there.

    Second query aggregates all the reports by product category and give its count... within the period of time specified...


    I wanted to create only one query which does that!, but I still cannot.

    by the way, there are two tables in play: tblreportproduct and tblreport

    The tblreportproduct contains all the transactions from a report... so a report can have many different products

    the tblreport contains the ActivityDate ---(the form Report contains the subform ReportProduct)

    Both tables are linked via the ReportID.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Please use the same names from your first post - there are no fields call Product or Product Category, so I am confused!

    I just want the query to give me the count of the products by product category in a specific period of time.
    Group by Product category
    Where period of time
    Count records

    Or if you need a prior query which first gets all unique product records, then use this query to count the records.

  5. #5
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Sorry, I mixed them.. but it is the same idea...


    main query: "qryProdCategory"

    Code:
    SELECT tblReportProduct.ProdCategoryFROM tblReport INNER JOIN tblReportProduct ON tblReport.ReportID = tblReportProduct.ReportID
    GROUP BY tblReportProduct.ProdCategory, tblReport.ActionDate, tblReportProduct.ReportID
    HAVING (((tblReport.ActionDate) Between [Date1] And [Date2]));
    subquery: "qryProdTotalCategory" --- which gives me what I need..

    Code:
    SELECT qryProdCategory.ProdCategory, Count(qryProdCategory.ProdCategory) AS CountOfProdCategoryFROM qryProdCategory
    GROUP BY qryProdCategory.ProdCategory;

    but how can I create one query...???
    Attached Thumbnails Attached Thumbnails prodTotalCategory.JPG   prodCategory.JPG  

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    The query on the right: the ActionDate is "Where" and the ReportID is "Count".

    This will count every record - is this what you want? You say that the Action Date is duplicated on some records, do you want to count it only once or once for every record? Which would give you:
    Count how many times the product category and action date combination appear - is that it?

  7. #7
    Susy is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Sep 2014
    Posts
    134
    Hi aytee111,


    thanks for your interest.

    This is so good... Sometimes talking to you all help to understand what ones task is... I think I was doing something else.

    I want to add the qty by product category sold in a specific period of time.

    Voila!

    Thanks

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

Similar Threads

  1. Putting in safegaurd. Is it the best way.
    By Abacus1234 in forum Forms
    Replies: 5
    Last Post: 10-17-2016, 03:32 PM
  2. Putting the legend where I want it
    By Lou_Reed in forum Access
    Replies: 3
    Last Post: 09-10-2015, 09:41 AM
  3. Replies: 4
    Last Post: 12-05-2014, 11:15 AM
  4. Replies: 1
    Last Post: 12-19-2012, 10:46 PM
  5. Help with putting QUERY in a Range
    By taimysho0 in forum Programming
    Replies: 3
    Last Post: 02-15-2012, 06:29 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