简体   繁体   中英

Multi value parameter for multiple columns in SSRS

I'm building a report with SSRS, and have multiple columns filtered on multiple values, but I need the parameters that are passing values to be paired.

For example, I have a table with the following columns: Employee, TransDate, Hours, Comment Primary key in this table is a combination of Employee and TransDate (I cannot modify).

I need to be able to return multiple rows from this table with parameters @Employee and @TransDate. If I simply make both parameters MultiValue and use an IN statement in my WHERE, then I get a mix of both. For example if my parameters are: @Employee = 6899,5203 @TransDate = 01/09/2014,01/10/2014 Then I get 4 rows; each employee on each date.

I need my @Employee and @TransDate to be passed together (6899,01/09/2014) as a key value, with multiple instances of those parameters passed. I don't know how to put that together with SSRS and the WHERE IN statements on my SQL query.

I'm hoping I'm just missing something simple, but I can't figure this one out today.

You could add a third parameter to your report that allows the user to select from the list of available Employee/Date combinations that result from their selections in the Employee and Date parameters.

In this parameter you can create an artificial key that combines the Employee and TransDate values (and an associated user-friendly "label" column for display). The purpose of keeping the first two parameters for Employee and TransDate are to minimise the number of options available in this third parameter (you could of course just have only this third parameter without the filtering on Employee and TransDate, but this would probably result in an unusably large amount of possible values in the parameter list).

The SQL for the parameter values query would look something like this (assuming Employee is an integer and TransDate is a Datetime):

SELECT
  CONVERT(VARCHAR, Employee) + '_' + CONVERT(VARCHAR, TransDate, 112) AS ParamValue
  CONVERT(VARCHAR, Employee) + ' - ' + CONVERT(VARCHAR, TransDate, 103) AS ParamLabel
FROM
  TableName
WHERE
  (Employee IN (@Employee))
  AND (TransDate IN (@TransDate))

In your main dataset query you can then use the selected values from this parameter to return only the selected Employee/TransDate combinations:

SELECT Col1, Col2, COl3, bla , bla
FROM 
   TableName 
WHERE
   CONVERT(VARCHAR, Employee) + '_' + CONVERT(VARCHAR, TransDate, 112) IN (@Parameter3)

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