如何在SSRS报告的查询中使用多值参数?

时间:2013-12-13 17:54:02

标签: tsql reporting-services bids sql-server-2012-express

我正在研究SSRS中的报告,该报告具有可以具有多个值的参数。我可以将一个Parameter值传递给查询就好了。我在查询多个值时使用IN @Paramter,我还使参数接受多个值。但是,当我想要所有值时,查询不起作用。

1 个答案:

答案 0 :(得分:2)

SO上有几个答案与将多值参数传递给SSRS中的数据集查询有关。看到这个 - > Passing multiple values for a single parameter in Reporting Services

我无法重现您描述的场景(选择一个值有效,但所有值都不起作用)。但是,我使用SQL Server 2008作为数据源实现了上面链接(Minks)中的一个答案。以下是详细信息:

我有一个名为@ReportParameter1的参数,它是从以下数据集查询填充的(Value field = id,Label field = description):

select 1 as id, 'choice1' as description union
select 2 as id, 'choice2' as description union
select 3 as id, 'choice3' as description union
select 4 as id, 'choice4' as description

然后我将报告数据集查询为:

select * from 
(select 1 as id union
 select 2 as id union
 select 3 as id union
 select 4 as id) x
 where id in (@ReportParameter1)

在报表数据集的“参数”选项卡下,我为@ ReportParameter1设置了以下表达式:

=Split(Join(Parameters!@ReportParameter1.Value,","),",")

如果我为@ReportParameter1选择所有值,则查询有效地变为:

select * from 
(select 1 as id union
 select 2 as id union
 select 3 as id union
 select 4 as id) x
 where id in (1,2,3,4)