简体   繁体   中英

Hiding Sub report in SSRS based on Parameter (and not executing the Stored Procedure)

I have an issue where I wish to hide/show a sub-report based on a parameter that is passed to the main report.

I can set the hidden property using an expression which will hide/show the sub-report, but what I found using SQL Profiler, is that the sub-report stored procedure is still executed, even if the sub-report is hidden.

Is anybody aware of a way to avoid this, other than changing the stored procedure itself. If not, does anybody know the reason why the stored procedure is executed even thought the sub-report is hidden?

Hidden report elements in SSRS are still processed - the hidden property simply determines whether they are displayed in the output.

One way to ensure that the procedure is only executed conditionally would be to change the name of the stored procedure in the dataset to an expression - something like:

=iif(Parameters!RunMyDataset.Value="Y","sp_MyDataSet","sp_Dummy")

- where sp_Dummy is a stored procedure that performs minimal processing (eg. SELECT NULL ).

There's a method to solve this. Base on your description of the question. For example, you have 4 subreports and named them page1 through page4. And main report will pass a parameter "Investor_ID" value to all these 4 pages. In the main report, you need to create 4 boolean parameters and set hidden property of the subreport to control these 4 subreports visible or not.

For instance, Use expression =iif(Parameters!Page1.Value = true, false, true) so that when you select true for parameter page1 then page1 will be shown otherwise it will be hidden.

Then you need to config parameters in "Subreport Properties" for subreports.

For Parameter Investor_ID, which the subreport needed, in the value choose expressing and use =IIF(Parameters!Page1.Value = true, Fields!Investor_ID.Value, nothing) . That means if you choose hide page1 then mainreport will pass nothing to subreport page1. Then Page1 will not be run and will show "Error: Subreport could not be show" since the Investor_ID parameter is null. But we hide that subreport. So page1 will not show up.

In this way you can control the hidden subreport execute or not.

  1. Right-click on the sub report object in the main report and select “Format Subreport…”. This will open the Format Editor.

  2. Select the “Subreport” tab in the Format Editor.

  3. place a check mark in the “Suppress Blank Subreport” check box.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM