How to use IN operator in a query SQL with Reporting Services multi value parameter

Daniele Barso 1 Reputation point
2022-10-12T17:43:21.043+00:00

I need to create a parameter where user insert a list of values.

The Data Set query have to contain a IN operator on the parameter values

Is it possible?

Many thanks for yuor help

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,061 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2022-10-12T18:19:11.75+00:00

    Yes, it is the common approach. Set the parameter to be multi valued. Then in your dataset where clause use the IN operator in combination with the parameter name and SSRS will handle the rest. Refer to an example article here. There are other examples available online as well.

    0 comments No comments

  2. Joyzhao-MSFT 15,631 Reputation points
    2022-10-13T01:50:44.087+00:00

    Hi @DanieleBarso-1340 ,
    When creating a multivalued parameter, the text of the query variable must contain the IN operator, and be sure to include parentheses around the variable, as follows:

    WHERE Production.ProductInventory.ProductID IN (@ProductID)  
    

    See more: Add a multi-value parameter to a paginated report.
    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.

    0 comments No comments

  3. Anonymous
    2022-10-14T02:28:27.227+00:00

    Hi @Daniele Barso
    I can do a simple test for you. Here is my raw data.
    250189-1.png
    Now I want to create a parameter "key" to control "MATCHESPRIMARY", so I add this statement to the query.
    250278-2.png
    After clicking OK, we can find that a parameter "key" appears under Parameters. In its properties box, we may need to set its available values, default values, etc. Since the test I did was relatively simple, I just checked Allow multiple values.
    250200-3.png
    After running, enter "1" and "2", and the data whose MATCHSPRIMARY values are "1" and "2" can be displayed.
    250210-4.png
    For more details, you can refer to this link: add-a-multi-value-parameter-to-a-report.
    Best regards,
    Aniya

    0 comments No comments

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.