在标题中使用报告参数
我读过 其他帖子建议在标题中显示动态数据时使用参数,因为它可以在 pdf 中正确呈现。我正在尝试实施该解决方案,但遇到了问题。当参数返回数据时它会起作用,但如果没有返回数据,它会抛出错误。这是我的设置:
- 隐藏
- 允许空值
- 允许空白值
- 可用值:来自查询
- 默认值:来自查询
我的标题中的文本框具有以下值:
=IIf(IsNothing(Parameters![Report Parameter Name].Value), "", Parameters![Report Parameter Name].Value)
当未返回默认值的行时,它会显示错误:
“[报告参数名称]”参数缺少值。
我是报告服务的新手,所以我可能会错过一些大概念。对我来说,返回的数据不符合允许空值标准。
I've read other posts that recommend using parameters when displaying dynamic data in the header because it renders correctly in pdf. I am trying to implement that solution but have run into an issue. It works when data is returned for a parameter, but it throws an error if data is not returned. Here is my setup:
- Hidden
- Allow null value
- Allow blank value
- Available values: From query
- Default values: From query
The textbox in my header has the following value:
=IIf(IsNothing(Parameters![Report Parameter Name].Value), "", Parameters![Report Parameter Name].Value)
When a row is not returned for the default value, it displays the error:
The '[Report Parameter Name]' parameter is missing a value.
I'm new to reporting services so I may be missing some large concept. To me, no data returned fits the Allow null value criteria.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 IsNothing 的情况以及类似的被零除的情况下使用 IIF 的问题在于它不是语言构造,它实际上是一个函数。因此,参数在调用函数之前计算,这意味着您认为不应该计算的表达式实际上是在函数调用之前计算的。
我知道 IF 表达式的 true 和 false 部分都被计算似乎很疯狂,但将其视为函数调用而不是语言功能。不存在像语言中那样的路径短路,错误在于调用函数之前计算所有参数。
您可以将其替换为自定义代码函数,以达到与您想要的相同效果。因此,大致如下:
右键单击报告正文并选择“属性”。单击“代码”选项卡并输入以下代码:
然后在标头中调用它,如下所示:(
我不在系统前测试它,但您应该明白这个想法)
The problem with using IIF in cases with IsNothing and also in similar divide by zero cases is that it is not a language construct, it is actually a function. Therefore, the parameters are evaluated before calling the function, which means that the expression that you think shouldn't be evaluated IS actually evaluated before the function call.
I know it seems crazy that both the true and false parts of an IF expression are calculated but think of it as a function call and not a language feature. There is no path short circuiting like in a language, the error is in the calculation of ALL the parameters prior to calling the function.
You can replace this with a custom code function to do the same effect that you are after. So something along the following lines:
Right-click the body of the report and choose Properties. Click the Code tab and enter the following code:
Then call it in your header like so:
(I'm not in front of a system to test this on but you should get the idea)