Search code examples
reporting-servicesssrs-2008ssrs-tablix

SSRS generate same report for multiple values accepted as parameters


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.


Solution

  • 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.    │
    └─────────┘