Thursday, February 23, 2012

Multiple Value Parameter in Subreport

Here's the scenario--
You're using a Crystal Reports 'Command' to run your SQL statement. Next thing you know, you need one of your parameters to support "multiple" input options. Short answer, not possible with only 1 report; however, there is a work around this issue.

Performance is a huge reason as to why you would want to run an embedded parameter with your command. If you filter the data at the "Record Selection" level, the query fetches all the data first, and then applies the parameter. With the approach below, you will fetch the data CONDITIONED on your parameter. Hope this makes sense...

Here's How:
Assumptions: Crystal Reports XI
DB: Oracle 10gR2
1. Create a main report and create a parameter called - PM1.
2. Set "Allow multiple Values" flag to 'True' on PM1:
3. Create new formula call it: ConcatPM1

Copy This: "'"&Join({?PM1},"','")&"'"

4. Create new subreport with Command and create a parameter in the command called concat_param (you will link this to @ConcatPM1) and use the IN clause to set it equal to the field you're conditioning the data to:

DB_FIELD IN (?concat_param)
5. Add subreport to the Page Header of master report
6. Right Click on subreport, and select "Change Subreport Links"
7. On "Fields to link to" drag over @ConcatPM1 and tie to ?concat_param in your subreport (my screenshot is using differen names, but you should get a sense of what I mean)







8. Run your main report, everything should work now!!!

Hope this saves some time on your next project.