Reporting Services,在算术运算期间出错

时间:2018-07-04 09:54:39

标签: sql tsql reporting-services

我试图在SQL Server Reporting Services中获得两个日期之间的差异。我有离开日期,以及下一个到达日期。我使用两个iif来计算第一天的天数,以及第二个iif的小时,分​​钟和秒。

=iif(IsNothing(Fields!NextEnterDateTimeUtc.Value)=False,

Floor(DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value) / 86400)

& iif(Floor((DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value)) / 86400)=1," day ", " days ") & 

Format(DateAdd("s", DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value), "00:00:00"), "HH:mm:ss")

, "No data")

问题是,在计算之后,当没有Fields!NextEnterDateTimeUtc.Value的数据时,出现以下错误:Expression The hidden value in the text "Textbox20.Paragraphs [0] .TextRuns [0]" contains an error: An overflow occurred during the arithmetic operation.

1 个答案:

答案 0 :(得分:0)

问题出在你的表情部分

DateAdd("s", DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value), "00:00:00")

即使条件为假,Iif也会计算所有表达式

您需要额外的Iif才能始终为Dateadd返回有效值

   DateAdd("s", Iif(IsNothing(Fields!NextEnterDateTimeUtc.Value)=False,DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value),0)

下面是完整表达式

= iif(IsNothing(Fields!NextEnterDateTimeUtc.Value)=False,

Floor(DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value) / 86400)

& iif(Floor((DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value)) / 86400)=1," day ", " days ") & 

Format(DateAdd("s", Iif(IsNothing(Fields!NextEnterDateTimeUtc.Value)=False,DateDiff(DateInterval.Second, Fields!LeaveDateTimeUtc.Value, Fields!NextEnterDateTimeUtc.Value),0), "00:00:00"), "HH:mm:ss")

, "No data")