How to select all parameter values in SSRS?

一个人想着一个人 提交于 2019-12-12 05:49:41

问题


I have a parameters @Year and @Month in my report, where month has assigned values like January(label): 1(values), February: 2, ... My datased is feeded by stored procedure which has a filter

WHERE (cal.CalendarYear = @Year) AND (cal.MonthId = @Month)

When I check 'Allow multiply values' in parameter settings, it returns an error

Error converting data type nvarchar into int.

How can I select all values (by default)?


回答1:


If you don't need to use a Stored Proc you can easily solve the problem.

Copy the SQL from your stored proc (excluding the PROC definition, just the main code) and paste it in as your dataset query.

Change your = @Year and = @Month to IN(@Year) and IN(@Month)

That's all there is to it, no joining, splitting or anything else.

SSRS will inject the parameter values as comma separated values correctly for you.




回答2:


When you select multiple values, you pass the parameter to the procedure as an expression with Join().

Then in your procedure change your month parameter to be of type nvarchar(max).

Create a temp table and use a t-sql split string function (Google this, there are so many varieties but if you're stuck we can find one) to split the string into a table. Then inner join to your table in your procedure to filter on the selections.




回答3:


Your error message about "nvarchar into int" suggests a data type mismatch between your SSRS parameter and your MonthId column. Check the Report Parameter Properties -> General -> Data type for the former and your table schema for the latter, and make sure they're either both text/varchar or both integers.

Allowing your query to handle multiple parameter values should be much simpler than needing to use joins and splits. Just use IN instead of =, and put your parameter name inside a set of brackets.

AND (cal.MonthId IN (@Month))

To set the defaults for your parameter, go to the Report Parameter Properties -> Default Values. Select the Specify values option, and add your numbers 1-12 as separate Value records.



来源:https://stackoverflow.com/questions/45012713/how-to-select-all-parameter-values-in-ssrs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!