SQL 将多值参数传递给子报表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13725622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing multivalue parameter to a subreport
提问by monican
I'm having a problem when working with multivalue
parameters between reports.
multivalue
在报告之间处理参数时遇到问题。
I have a main report in which I have defined a multivalue paramer, which I use to run a SQL query to populate its dataset. The parameter is used in the WHERE clause in the following way:
我有一个主报告,我在其中定义了一个多值参数,我用它来运行 SQL 查询来填充其数据集。该参数在 WHERE 子句中的使用方式如下:
WHERE values IN (@parameter)
It's working fine and it retreives the expected data.
它工作正常并且可以检索预期的数据。
Then this main report passes this parameter to a subreport. The parameter is also defined as multivalue in the subreport and, as far as I can see in the parameter's dropdownlist it receives the values in the right way. Something like this: A, B, C
然后这个主报表将此参数传递给一个子报表。该参数在子报表中也被定义为多值,据我在参数的下拉列表中看到,它以正确的方式接收值。像这样:A,B,C
The thing is that the query that populates the subreport's dataset returns nothing. It also has a WHERE clause defined as in the main report (which is already working)
问题是填充子报表数据集的查询不返回任何内容。它还有一个 WHERE 子句在主报告中定义(已经在工作)
WHERE values IN (@parameter)
If I run the query manually, hardcoding the values to something like this:
如果我手动运行查询,将值硬编码为如下所示:
WHERE values IN ('A', 'B', 'C')
it works, but when I try to use the parameter it doesn't. So, somehow it's losing the format or the values in the way.
它有效,但是当我尝试使用该参数时却无效。所以,不知何故,它正在丢失格式或值。
I tried this solution in the subreport's dataset definition, which was proposed in another thread:
我在子报表的数据集定义中尝试了这个解决方案,这是在另一个线程中提出的:
=join(Parameters!<your param name>.Value,",")
But it doesn't work for me, the dataset is still empty.
但它对我不起作用,数据集仍然是空的。
Any ideas about what I'm missing?
关于我缺少什么的任何想法?
Thanks! :)
谢谢!:)
采纳答案by monican
Just created the report from scratch again and it worked. I must have forgotten something in the middle.
刚刚从头开始重新创建报告并且它起作用了。我一定是忘记了中间的东西。
Anyway, just in case somebody needs it, the two parameters, the one in the main report and the one in the subreport , must be defined as multivalue.
Then in your query you should use IN
in your WHERE
clase, something like this:
无论如何,以防万一有人需要它,两个参数,主报表中的一个和子报表中的一个,必须定义为多值。然后在您的查询中,您应该IN
在您的WHERE
类中使用,如下所示:
WHERE field IN (@parameter)
And nothing else is needed. I didn't need to do the following:
不需要其他任何东西。我不需要执行以下操作:
=join(Parameters!<your param name>.Value,",")
It just worked for me
它只对我有用
回答by Jamie F
This should "just work." Make sure that the Parameter in the subreport is set up as multivalue, and I usually use the exact same query as in the parent report to provide "Available Values."
这应该“正常工作”。确保子报表中的参数设置为多值,我通常使用与父报表中完全相同的查询来提供“可用值”。
Check that you are passing the entire parameter to the subreport: In subreport properties on the parent report, the parameter's value should read [@MyParamName]
not <<Expr>>
. If it reads as the latter, edit the expression and make sure it doesn't have a (0) at the end. but =Parameters!MyParamName.Value
is correct, not=Parameters!MyParamName.Value(0)
检查您是否将整个参数传递给子报表:在父报表的子报表属性中,参数的值应为[@MyParamName]
not <<Expr>>
。如果读取为后者,请编辑表达式并确保其末尾没有 (0)。但是=Parameters!MyParamName.Value
是正确的,不是=Parameters!MyParamName.Value(0)
回答by Swanny
I think I know what you did, as I was drawn here by having the same problem.
The subreports were setup fine, but when entering the parameter binding in the parent report, the Value
drop down did offer my parameter, so I used expression builder to select it. This left the grey << Expr >>
marker in the value and would only work when I had only one value selected from the list. When I replaced this with [@MyParam]
it worked fine regardless of the number of values selected. When I had a look at the value expression builder had created a bit closer it had =Parameters!MyParam.Value(0)
. Removing the (0)
also fixes it.
我想我知道你做了什么,因为我遇到了同样的问题。子报表设置得很好,但是在父报表中输入参数绑定时,Value
下拉菜单确实提供了我的参数,所以我使用表达式生成器来选择它。这<< Expr >>
在值中留下了灰色标记,并且仅当我从列表中只选择了一个值时才起作用。当我用[@MyParam]
它替换它时,无论选择的值数量如何,它都可以正常工作。当我查看创建的值表达式构建器时,它更接近它了=Parameters!MyParam.Value(0)
。删除(0)
也修复它。