Pass Query Parameter to Subquery

Posted on 2006-05-04
Last Modified: 2007-12-19
Hello, experts!  I have a question regarding Crystal Reports XI.  I have a report that pulls data from 3 different tables.  One table returns 'header' type of data (one row), while the other two tables return 'detail' data (multiple rows).  

What I've done is created a report using

SELECT * FROM my_header_table WHERE order = {?order} (for example)

and I have two subreports:

SELECT * FROM my_detail_table1 (for example)
SELECT * FROM my_detail_table2 (for example)

These are linked to the main report through subreport links. This takes an exceedingly long time to run.  If I change my subreports to:

SELECT * FROM my_detail_table1 WHERE order = {?order}  

(with no subreport links) then the report runs much more quickly.  The problem is that the user must then enter the same number 3 times.  Can I pass the parameter from the header table to the queries in the subreports?

Question by:mixxie
    LVL 100

    Assisted Solution

    Any reason you can't join the tables and avoid the need for a subreport?

    You should be able to link the main report parameter to the subreport parameter on the subreport link page.

    LVL 8

    Accepted Solution

    first = concur with mlmcc = for a shor term/mmediate solution, use the <change subreport links> dialog box to create a link between the main report and each subreport (reach this dialog box by <right clicking> on each subreport, and then choosing this option... It looks like for your situation, you will also check the box regarding selecting records within the subreport based upon the link... (note: this will not speed up the report because the subreport runs its query multiple times...)

    second = also concur with mlmcc - you might want to see if you can modify your sql query to eliminate the need for the subreports entirely... this can likely be done via a Union Query (based upon the look of your information above) and or other linking... did you want to expalin a bit further what information you are working with and/or why you need the 2 subreports (e.g. could "groups" based upon formulas work as well for you, etc.... so, please provide a bit more details so that we can help you better evaluate your needs...

    best wishes, :) Pat K
    LVL 8

    Expert Comment

    woks fo me - thanks, mlmcc :)
    LVL 100

    Expert Comment

    Glad i could help


    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
    Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now