现场不同结果的不同“IF”声明 - SSRS

时间:2017-01-23 20:16:30

标签: sql reporting-services ssrs-2008-r2

美好的一天,

我正在创建一个报告,我想根据字段中的变量分配一个唯一的"IF"语句。

例如,在某列中,如果某行显示"MCAD",我希望它在旁边的列中计算此公式:

iif(Fields!jhapostingdate.Value>"12/30/2016",(Sum(Fields!CurrentBalance.Value)-1803418)/6000000," ")

如果该行显示"RGAD",我希望它在旁边的列中计算此公式:

iif(Fields!jhapostingdate.Value>"12/30/2016",(Sum(Fields!CurrentBalance.Value)-6977142)/10000000," ")

依旧等等......

我理解以下表达方式不正确,但它可能会让我明白我的意图:

=iif(Fields!OfficerCode.Value="mcad",(iif(Fields!jhapostingdate.Value>"12/30/2016",(Sum(Fields!CurrentBalance.Value)-1803418)/6000000," "),"")

,iif(Fields!OfficerCode.Value="rgad",(iif(Fields!jhapostingdate.Value>"12/30/2016",(Sum(Fields!CurrentBalance.Value)-6977142)/10000000," "),"")

,iif(Fields!OfficerCode.Value="srf",(iif(Fields!jhapostingdate.Value>"12/30/2016",(Sum(Fields!CurrentBalance.Value)-3427940)/3000000," "),"")

,iif(Fields!OfficerCode.Value="maf",(iif(Fields!jhapostingdate.Value>"12/30/2016",(Sum(Fields!CurrentBalance.Value)-6977142)/10000000," "),"")

是否有特定的功能或表达方式?

感谢任何输入!

1 个答案:

答案 0 :(得分:0)

您可以使用Switch

来简化它
=Switch(
Fields!OfficerCode.Value="mcad",
  iif(Fields!jhapostingdate.Value>DateSerial(2016,12,30),(Sum(Fields!CurrentBalance.Value)-1803418)/6000000," "),
Fields!OfficerCode.Value="rgad",
  iif(Fields!jhapostingdate.Value>DateSerial(2016,12,30),(Sum(Fields!CurrentBalance.Value)-6977142)/10000000," "),
Fields!OfficerCode.Value="srf",
  iif(Fields!jhapostingdate.Value>DateSerial(2016,12,30),(Sum(Fields!CurrentBalance.Value)-3427940)/3000000," "),
Fields!OfficerCode.Value="maf",
  iif(Fields!jhapostingdate.Value>DateSerial(2016,12,30),(Sum(Fields!CurrentBalance.Value)-6977142)/10000000," "),
true,""
)

也可能需要使用DateSerial函数来创建硬编码日期:

DateSerial(2016,12,30)将生成12/30/2016日期,而"12/30/2016"只是一个字符串。您也可以使用CDate("2016-12-30")

如果有帮助,请告诉我。