问题描述
使用SSRS 2008 R2并想知道是否可以为多值参数中选择的每个值生成子报告?
using SSRS 2008 R2 and wondering, if is possible to generate sub-report for each value selected in multi-valued parameter?
假设您有一个多值参数"parameterA",并且选择了四个值(Value1,Value2,Value3和Value4).我想为每个这些值生成子报告(将值作为单个参数传递).当然,我可以更改过程以处理多值参数,但是由于性能和缓存,我真的不想这么做.
Lets imagine you have multi-valued parameter "parameterA" with four values selected (Value1, Value2, Value3 and Value4). I'd like to generate sub-report for each of these values (passing the value as single parameter). Sure, I can change the procedure to handle multi-valued parameter, but because of performance and caching I really don't want to.
谢谢您的建议.
推荐答案
为此,您必须将子报表放入列表或tablix中.据我所知,没有一种简单的方法可以让该列表或Tablix遍历多值参数中的值.它只会接受一个数据集.
To do this you would have to put the subreport into a list or tablix. As far as I know there's no easy way to have that list or tablix iterate over the values in a multi-valued parameter. It will only accept a dataset.
因此,我能想到的唯一解决方法是将参数拆分为数据集中的一组行,这对于SQL来说是可行的,但并非微不足道.但是,如果参数的可用值来自数据集,情况将会有所改善:您只需将tablix/列表挂接到数据集并过滤参数中未选择的项目即可.
So the only workaround I can think of involves splitting the parameter into a set of rows in a dataset, which is possible but not trivial with SQL. However, if the available values for the parameter come from a dataset the situation would improve: you can just hook the tablix/list to your dataset and filter items that aren't selected in the parameter.
编辑:通过将数据集查询构建为表达式,我发现了一种将将多值参数扩展到数据集中的解决方案.假设参数@MultiParamX
,此表达式将创建一个查询,该查询将在一个列中输出所有选定的值:
I've found a slightly hackish solution to expanding a multi-valued parameter into a dataset, by building the dataset query as an expression. Assuming a parameter @MultiParamX
this expression will create a query that outputs all selected values in one column:
="SELECT '"
&
Join(Parameters!MultiParamX.Value, "' MyParam UNION ALL SELECT '")
&
"' MyParam"
这可能会生成如下查询(为便于阅读而重新格式化):
This may generate a query such as the following (reformatted for readability):
SELECT 'A' MyParam
UNION ALL
SELECT 'B' MyParam
UNION ALL
SELECT 'C' MyParam
-- Etc. for all selected values
这将生成一个结果集,例如:
This will generate a result set such as:
┌─────────┐
│ MyParam │
├─────────┤
│ A │
│ B │
│ C │
│ Etc. │
└─────────┘
这篇关于SSRS 2008-多值参数中每个值的子报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!