在IF语句SSRS中使用多个子句时出错

时间:2016-09-26 19:07:56

标签: reporting-services ssrs-2012

我很难在SSRS中使用带有多个子句的if语句。

我正在使用表达式:

=IIF(DateDiff("d",Fields!Project_Target_Date.Value, Now())>-14 AND DateDiff("d",Fields!Project_Target_Date.Value, Now())<-1, "Yellow") OR IIF(DateDiff("d",Fields!Project_Target_Date.Value, Now())>-1, "Red",  "Black")

我得到了错误:

The Color expression for the textrun ‘Project_Target_Date.Paragraphs[0].TextRuns[0]’ contains an error: [BC30516] Overload resolution failed because no accessible 'IIf' accepts this number of arguments.

我希望将目标日期的颜色设置为在目前的2周内显示为黄色,如果目标日期已经过去,则显示红色,否则显示为黑色。

我想我会遗漏/忽略一些简单的事情。

任何帮助将不胜感激!

谢谢!

2 个答案:

答案 0 :(得分:0)

你正在将你的IIF嵌套错误。你可以使用类似的东西:

=IIF(DateDiff("d",Fields!Project_Target_Date.Value, Now())>-14 AND DateDiff("d",Fields!Project_Target_Date.Value, Now())<-1, "Yellow",IIF(DateDiff("d",Fields!Project_Target_Date.Value, Now())>-1, "Red",  "Black"))

答案 1 :(得分:0)

试试这个:

=IIF(
  DateDiff("d",Fields!Project_Target_Date.Value, Now())>-14
  AND 
  DateDiff("d",Fields!Project_Target_Date.Value, Now())<-1, "Yellow",
  IIF(
   DateDiff("d",Fields!Project_Target_Date.Value, Now())>-1, "Red","Black"))

我更喜欢使用Switch而不是嵌套的IIF:

=Switch(
  DateDiff("d",Fields!Project_Target_Date.Value, Now())>-14 AND
  DateDiff("d",Fields!Project_Target_Date.Value, Now())<-1,
  "Yellow",
  DateDiff("d",Fields!Project_Target_Date.Value, Now())>-1,
  "Red",
  true,"Black"
)

如果有帮助,请告诉我。