SSRS Multiple Value parameter filter based on dataset

后端 未结 2 889
天涯浪人
天涯浪人 2021-01-21 15:54

Say I have a dataset in SSRS called DataSet1 that looks like this:

CREATE TABLE #data 
(ID int, Value int, UserID varchar(2))
INSERT INTO #data VALUES
(1, 1000,          


        
2条回答
  •  没有蜡笔的小新
    2021-01-21 16:53

    You will have to have a separate data set for your parameter query and yes you got that part right, for the given data set:

    SELECT DISTINCT UserID
    FROM TABLE
    

    This query will be used to populate the drop down list of your parameter. (Multiple values allowed or not).

    For you Main query:

    if you allow Multiple Selection for @UserID parameter you will write you main Data set query with IN operator as below:

    SELECT ID, Value, UserID
    FROM table
    WHERE (UserID IN (@UserID)) 
    

    If you only want users to be able to select only one value at a time the you can write the above query with a where clause something like WHERE UserID = @UserID.

    Make sure you map the variables correctly. But you will have to have a separate query for your drop down list.

提交回复
热议问题