Hiding Sub report in SSRS based on Parameter (and

2019-01-15 11:07发布

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?

3条回答
ゆ 、 Hurt°
2楼-- · 2019-01-15 11:35
  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.

查看更多
神经病院院长
3楼-- · 2019-01-15 11:48

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).

查看更多
放荡不羁爱自由
4楼-- · 2019-01-15 11:55

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.

查看更多
登录 后发表回答