SSRS report using a Stored Procudure. - Passing Multi-Valued Parameter -- I thought you HAD to add a JOIN clause for the parameter in the RDL?

LH 26 Reputation points
2022-09-14T00:26:44.547+00:00

I've been developing SSRS reports and I thought in an RDL, you HAD to use a JOIN clause for a Stored Procedure data set that consumes a parameter referencing a Multi-Valued report parameter
-- like this =Join(Parameters!ClientCountry.Value, ",")

...And then a String_Split within your Stored procedure

  1. Is it correct that in the RDL for a Stored Procedure data set - you just have to reference the Multi-Valued parameter like [@ClientCountry] and NOT =Join(Parameters!ClientCountry.Value, ",")?
  2. If you need to use a different delimiter, like a Pipe delimiter, do you then HAVE to set the Stored Procedure data set parameter values to =Join(Parameters!ClientCountry.Value, "|")?
  3. Whatever the answer, has it always been like that or did something change in an SSRS version?
  4. Does it matter if the Multi-Valued report parameter feeding that SP gets its value from an SP itself or a Text query?

Thanks for your response!

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
3,057 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Joyzhao-MSFT 15,631 Reputation points
    2022-09-14T05:03:26.127+00:00

    Hi @LH ,

    1. Pass the multi-value parameter to the stored procedure as a comma-separated string by setting the parameter expression in the SSRS Dataset Properties: =JOIN(Parameters!ClientCountry.Value,",")

    2) If you need to use a different delimiter, like a Pipe delimiter, Please change =JOIN(Parameters!ClientCountry.Value,",") to =JOIN(Parameters!ClientCountry.Value,"|"), and change the stored procedure to use a where clause like this:

    Where prod.Color in (Select value from string_split(@Color,'|') where RTRIM(value)<>'')  
    

    That is, it uses string_split to split the passed value into a table, then selects from that table and checks for membership with 'in'.

    3) Since SQL Server 2016, you can use built-in functions for this.

    4) We cannot call the stored procedure in Text query, please select "Stored Procedure" in the dataset query type.

    Please refer to the following article : SSRS : How to pass multi-value Parameter to a Stored Procedure.
    Best Regards,
    Joy


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. LH 26 Reputation points
    2022-09-15T22:38:04.043+00:00

    Thank you @Joyzhao-MSFT ,

    I do understand what you are saying about the Multi-Value parameters stored as an Array.
    However, if that is true, then why for the dataset with the Stored Procedure that accepts Multi-Value parameters [@ClientGroup] and [@DebtorCode] -- why would SSRS pass in Comma delimited strings as seen in SQL Profiler since I am not using =JOIN(Parameters!ClientCountry.Value,",") but instead padding in [@ClientGroup]?
    In this image, the SP with string values being passed in is copied over from SQL Profiler -- that is what is actively being passed when I run the report.

    241652-commadelimited.png


  3. Devin McMahon 0 Reputation points
    2023-06-20T16:09:08.2466667+00:00

    I am working on this now, and I have followed all instructions

    1. Multi-valued parameter with JOIN(Parameters.pMultiSelect .Value,",") in the Expression in SSRS
    2. Putting the values into a TEMP table in the Stored Procedure
    3. using (Select value from string_split(@pMultiSelect,',') where RTRIM(value)<>'')
    4. Joining Temp table to real table to return the correct values

    If I run the Stored Procedure, and set the value of the Parameter to N"Value1,Value2,Value3" (meaning I am feeding it a list of comma separated values directly) in Query analyzer the SP runs successfully

    If I set the value of the Multi-Select Parameter to Value1,Value2,Value3 - then execute the Report it throws no error and returns NOTHING

    As troubleshooting I have the JOIN(Parameters.pMultiSelect .Value,",") showing on the header of the report and it returns Value1,Value2,Value3 correctly

    If I look at SSRS execution log, the parameter is NOT being passed as pMultiSelect =Value1,Value2,Value3 but is instead being processed as pMultiSelect=Value1&pMultiSelect =Value2&pMultiSelect=Value3 so it is splitting it up front and as a result, the query returns nothing.

    So, I have no idea why it is doing that, but I have reviewed all the available articles and I believe I am doing everything correctly. This is SSRS 2019


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.