sql - SSRS 中的计算
问题描述
我在下面的 SSRS 表达式中使用。基本上计算基于 SSRS 报告中的两个文本字段,如下所示。ReportItems!Amount6.Value
如果没有价值或记录,我仍然会出错
。
=iif(reportitems!Amount.Value = 0 or reportitems!Amount6.Value = 0 or Len(reportitems!Amount.Value) <= 0 or Len(reportitems!Amount6.Value) <= 0, NOTHING, (ReportItems!Amount.Value - ReportItems!Amount6.Value) / ReportItems!Amount6.Value)
=iif(reportitems!Amount.Value = 0 or reportitems!Amount6.Value = 0 or Len(reportitems!Amount.Value) <= 0 or Len(reportitems!Amount6.Value) <= 0, NOTHING, (ReportItems!Amount.Value - ReportItems!Amount6.Value) / ReportItems!Amount6.Value)
解决方案
IIF 是一个函数,而不是流控制
所以每个参数都会被执行,如果你想有条件地除法,你必须在它为空或为零时将除法器设置为1,当除法器为空或为零时不返回任何内容,你也可以使用cdec(表达式)转换为十进制,这样你就不必处理什么都没有的情况
=iif(cdec(reportitems!Amount.Value) = 0 or cdec(reportitems!Amount6.Value) = 0 or Len(reportitems!Amount.Value) <= 0 or Len(reportitems!Amount6.Value) <= 0, NOTHING, (cdec(ReportItems!Amount.Value) - cdec(ReportItems!Amount6.Value)) / iif(cdec(ReportItems!Amount6.Value) == 0,1,cdec(ReportItems!Amount6.Value)))
推荐阅读
- .net-core - 积极的 F# 编译器优化是否只发生在引用的依赖项 + 发布配置上?
- elasticsearch - 弹性搜索 - 节点故障
- discord.net - Discord.net 如何提及角色
- powerbi - 是否可以将 2 个或 3 个 SSAS Cube 连接到 Power bi 并创建视图?
- javascript - 位置问题:包含按钮的粘性页脚
- php - 如何使用 PHP 抓取单个linkedin 帖子
- html - 动态 SVG 模式作为背景:可能吗?我举个例子
- c++ - 错误:从 'std::__1::__wrap_iter 没有可行的转换
'到'int' - c - 数组中的二分查找
- javascript - NodeJS API 获取每个类别的 Items 数组