【问题标题】:Calculation in SSRSSSRS 中的计算
【发布时间】:2019-08-16 01:41:11
【问题描述】:

我在下面的 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)

【问题讨论】:

  • 为什么不通过数据集而不是计算字段来做呢?
  • 错误信息是什么?
  • 我已经在数据集上做过这样的“isnull(Amount,0) Amount”。但还是报错
  • 像这样给我“#Error”
  • 我猜你需要确保ReportItems! 的大小写正确。 SSRS 可能对这样的小事很挑剔。您引用的每个报告项是使用多个字段计算得出的,还是您可以简单地将它们称为 Fields!Amount.Value 或从查询中调用它们的任何名称?

标签: sql reporting-services


【解决方案1】:

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)))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多