Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2010
    Location
    Brandıs nad Labem - Czech Republic
    Posts
    36

    Question Report based on query + sub-report (1:N relation)

    Hi. I'm a bit lost in passing parameters, setting WHERE filters etc, so my report does not give me the information I want.

    I have 3 tables: A (with id, data1), B (with id, a_id (foreign key), data2), C (with id, b_id (f.k.), data3).

    I have one query:
    Code:
    SELECT A.data1, B.data2, B.id, COUNT(C.id) AS count_c, SUM(C.data3) AS sum_c
    FROM (A INNER JOIN B ON A.id=B.a_id) INNER JOIN C ON B.id=C.b_id
    GROUP BY B.id, B.data2, A.data1;
    I have a helper report (used as sub-report later), that is just like the table C.

    Ontop of the query above there is the main report. It embeds the sub-report.

    Here's how that should look like. The whole "Main Report" is populated from the query above (not directly from the tables A and B). The sub-report takes data from table C, as written above.



    But it doesn't look like this yet.



    So, what's ok and what's not:
    • As soon as I set the sub-report's master and child link I always get a poll dialog asking me for the value of "B". What's B by the way? B.id? The query therefore contains the B.id to be linked with the C.b_id of the sub-report.
    • If the above worked, the sub-report would be limited to records from C that linked to the same B record.
    • The query is not yet limited to one B.id. I want to do that from outside. Say I call the report from a button-press and there I know I want only stuff related to B.id = 7. What means are used to pass this information?


    Thanks for your interest, extra thanks for help!
    Last edited by BayerMeister; 08-17-2010 at 10:11 AM. Reason: refining

  2. #2
    Join Date
    Aug 2010
    Location
    Brandıs nad Labem - Czech Republic
    Posts
    36

    Lightbulb

    OK, I did this completely differently:
    • There is no big reason to have more than one query/table here - I changed the query so that the result contains columns of all 3 tables (a join over all 3 tables, WHERE B.id is given)
    • Therefore I didn't need a sub-report for a "sub-query", I used textboxes. In the body of the document components are duplicated for each record. Later I realized that placing a sub-report into the body makes even this component apper that many times as there are records to show. So the lesson: If you want to use a subquery, place it into the bottom of the page/report header.

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

Similar Threads

  1. Replies: 3
    Last Post: 05-21-2010, 03:57 PM
  2. Totals in a query-based report
    By babylikesburgh in forum Reports
    Replies: 4
    Last Post: 02-24-2010, 03:08 PM
  3. Report based on query shows no data
    By hbograd in forum Reports
    Replies: 2
    Last Post: 12-18-2009, 12:28 PM
  4. Replies: 1
    Last Post: 02-02-2009, 05:52 AM
  5. Problem with Report Based on a Query
    By gmalaret in forum Reports
    Replies: 1
    Last Post: 11-25-2008, 08:38 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