SSRS generate same report for multiple values accepted as parameters

不问归期 提交于 2019-12-25 06:59:20

问题


I need to generate the same report repeatedly for several values. I'm accepting these values using a multi-value parameter in a new report. I have also created a table with the original report as a subreport. How can I pass the values that the user selects in the parameter to this table? I have created a dataset, but I'm not able to bind these values to the dataset, which in turn is bound to the table. I have read several articles, however, I'm unable to get it working. Please advise.


回答1:


You bind the parameters in the main report, on the subreport object. In the sub-report, you apply those parameters to a dataset.




回答2:


I finally found the solution on another stackoverflow post after struggling for a few days.

Reproducing it here:

To do this you would have to put the subreport into a list or tablix. As far as I know there's no easy way to have that list or tablix iterate over the values in a multi-valued parameter. It will only accept a dataset.

So the only workaround I can think of involves splitting the parameter into a set of rows in a dataset, which is possible but not trivial with SQL. However, if the available values for the parameter come from a dataset the situation would improve: you can just hook the tablix/list to your dataset and filter items that aren't selected in the parameter.

Edit: I've found a slightly hackish solution to expanding a multi-valued parameter into a dataset, by building the dataset query as an expression. Assuming a parameter @MultiParamX this expression will create a query that outputs all selected values in one column:

="SELECT '" 
&
 Join(Parameters!MultiParamX.Value, "' MyParam UNION ALL SELECT '")
&
"' MyParam"

This may generate a query such as the following (reformatted for readability):

SELECT 'A' MyParam
UNION ALL
SELECT 'B' MyParam
UNION ALL
SELECT 'C' MyParam
-- Etc. for all selected values

This will generate a result set such as:

┌─────────┐
│ MyParam │
├─────────┤
│ A       │
│ B       │
│ C       │
│ Etc.    │
└─────────┘


来源:https://stackoverflow.com/questions/21603047/ssrs-generate-same-report-for-multiple-values-accepted-as-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!