简体   繁体   English

根据文本参数过滤数据集,该文本参数允许在SSRS中使用多个值

[英]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. 我有一个SSRS参数,该参数允许选择varchar类型的多个值。 How can I get my where clause to show all those selected in the parameter. 如何获取我的where子句以显示在参数中选择的所有子句。 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. 如果选择了前两个选项,则应该有2条记录。 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. 如果参数值同时返回“员工代码”和“员工姓名”,则在过滤之前,我将使用CTE(公用表表达式)创建串联的列。 You may want to create the CTE in a view if you're going to use it elsewhere. 如果要在其他地方使用它,则可能需要在视图中创建CTE。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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