Search code examples
sqlsql-server-2005ssrs-2008

Multi-valued parameter in SSRS 2008 isn't working


I have a parameter @Department and set its value in the Dataset to =Join(Parameters!Department.Value,","). I set it to accept multiple values and in my SQL I have the following clause: (RTRIM(G.DeptName) IN (@Department)).

It works whenever the user selects one department, but doesn't work at all whenever multiple departments are selected. It runs, but it doesn't display any data. For example, if I select 'Accounting', it shows 'Accounting' info. But if I select 'Accounting' and 'Marketing', nothing shows up.

Any ideas why this isn't working? Also, is it possible to do this in this manner with something other than "string" values?


Solution

  • You are making a false assumption.

    IN ('1,2,3,4') is very different from IN (1,2,3,4) or IN ('1', '2', '3', '4')

    What you are currently doing it the first one. You are checking whether your department name is in a list which is only one value long; the @department string. That value has commas in it, but it's still a single string, and so it's still a single item in the list.

    You have two options.

    Build up the SQL dynamically so that your list is part of the sql and not a string parameter.

    Or look up one of the many SPLIT() function available on-line. This is the one I recommend. You can then do something like...

    WHERE
      RTRIM(G.DeptName) IN (SELECT * FROM dbo.split(@Department))
    

    Or even better, join on the results of the SPLIT() function...

      yourTable AS G
    INNER JOIN
      dbo.split(@department) AS department
        ON  RTRIM(G.DeptName) = department.item