简体   繁体   中英

Filter a dataset based on a text parameter that allows multiple values in SSRS

I have an SSRS parameter that allows to select multiple values of type varchar. How can I get my where clause to show all those selected in the parameter. An example is if the parameter choices were

1 : Rob
2 : Tom
3 : Rick

If the first two choices were selected, there should be 2 records. Something to the effect:

where Employee.Code + ' : ' + Employee.Name IN ("1 : Rob","2 : Tom")

If the parameter value is returning both the "employee code" and "employee name", then I'd use a CTE (Common Table Expression) to create the concatenated column before filtering it. You may want to create the CTE in a view if you're going to use it elsewhere.

WITH
employee
AS
(
    SELECT tbl.* FROM (VALUES
      ( 1, 'Rob')
    , ( 2, 'Tom')
    , ( 3, 'Rick')
    ) tbl ([code], [name]) 
)
,
employee_values
AS
(
    SELECT 
          [code]
        , [name]
        , [code_name] = CAST([code] AS VARCHAR) + ' : ' + [name]
    FROM    
        employee    
)
SELECT 
      [code]
    , [name]
    , [code_name]
FROM 
    employee_values
WHERE 
    [code_name] IN(@Employee_Code)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM