需要在 Reporting Services 报告中根据以下逻辑显示日期范围,如下所示:
如果只有 Started datetime,则显示如下:
2014 年 12 月 12 日
如果同一天有 Started 和 Finished 日期时间,则显示如下:
2014 年 12 月 12 日上午 11:20 至下午 1:10
如果在不同日期有 Started 和 Finished 日期时间,则显示如下:
2014 年 12 月 12 日上午 11:20 至 2014 年 12 月 13 日下午 1:10 之间
我知道这很丑陋,但我有这个表达式来显示该字段:
=IIf(IsNothing(First(Fields!Finished.Value, "InspectionAdvice")), "on " & Day(First(Fields!Started.Value, "InspectionAdvice")) & " " & MonthName(Month(First(Fields!Started.Value, "InspectionAdvice"))) & " " & Year(First(Fields!Started.Value, "InspectionAdvice")) & " " &
IIf(
Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12,
Hour(First(Fields!Started.Value, "InspectionAdvice")) - 12,
Hour(First(Fields!Started.Value, "InspectionAdvice"))
)
& ":" & Minute(First(Fields!Started.Value, "InspectionAdvice")) & " " &
IIf(Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12, "pm", "am")
,
IIf(First(Fields!Started.Value.Date, "InspectionAdvice") = First(Fields!Finished.Value.Date, "InspectionAdvice")
, "on " & Day(First(Fields!Started.Value, "InspectionAdvice")) & " " & MonthName(Month(First(Fields!Started.Value, "InspectionAdvice"))) & " " & Year(First(Fields!Started.Value, "InspectionAdvice")) & " between " &
IIf(
Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12,
Hour(First(Fields!Started.Value, "InspectionAdvice")) - 12,
Hour(First(Fields!Started.Value, "InspectionAdvice"))
)
& ":" & Minute(First(Fields!Started.Value, "InspectionAdvice")) & " " &
IIf(Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12, "pm", "am")
& " and " &
IIf(
Hour(First(Fields!Finished.Value, "InspectionAdvice")) > 12,
Hour(First(Fields!Finished.Value, "InspectionAdvice")) - 12,
Hour(First(Fields!Finished.Value, "InspectionAdvice"))
)
& ":" & Minute(First(Fields!Finished.Value, "InspectionAdvice")) & " " &
IIf(Hour(First(Fields!Finished.Value, "InspectionAdvice")) > 12, "pm", "am")
, "between " & Day(First(Fields!Started.Value, "InspectionAdvice")) & " " & MonthName(Month(First(Fields!Started.Value, "InspectionAdvice"))) & " " & Year(First(Fields!Started.Value, "InspectionAdvice")) & " " &
IIf(
Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12,
Hour(First(Fields!Started.Value, "InspectionAdvice")) - 12,
Hour(First(Fields!Started.Value, "InspectionAdvice"))
)
& ":" & Minute(First(Fields!Started.Value, "InspectionAdvice")) & " " &
IIf(Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12, "pm", "am")
& " and " & Day(First(Fields!Finished.Value, "InspectionAdvice")) & " " & MonthName(Month(First(Fields!Finished.Value, "InspectionAdvice"))) & " " & Year(First(Fields!Finished.Value, "InspectionAdvice")) & " " &
IIf(
Hour(First(Fields!Finished.Value, "InspectionAdvice")) > 12,
Hour(First(Fields!Finished.Value, "InspectionAdvice")) - 12,
Hour(First(Fields!Finished.Value, "InspectionAdvice"))
)
& ":" & Minute(First(Fields!Finished.Value, "InspectionAdvice")) & " " &
IIf(Hour(First(Fields!Finished.Value, "InspectionAdvice")) > 12, "pm", "am")
)
)
如果 Started 和 Finished 都不为空,则一切正常。但是,如果 Finished 为空,那么我总是会得到 #Error。
现在,如果我删除包含嵌套 IIf 逻辑的 IIF 的第二部分,例如
=IIf(IsNothing(First(Fields!Finished.Value, "InspectionAdvice")), "on " & Day(First(Fields!Started.Value, "InspectionAdvice")) & " " & MonthName(Month(First(Fields!Started.Value, "InspectionAdvice"))) & " " & Year(First(Fields!Started.Value, "InspectionAdvice")) & " " &
IIf(
Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12,
Hour(First(Fields!Started.Value, "InspectionAdvice")) - 12,
Hour(First(Fields!Started.Value, "InspectionAdvice"))
)
& ":" & Minute(First(Fields!Started.Value, "InspectionAdvice")) & " " &
IIf(Hour(First(Fields!Started.Value, "InspectionAdvice")) > 12, "pm", "am")
,
"REMOVED"
)
当 Finished 为空时,事情就会起作用。
知道为什么我不能让丑陋的声明的两个部分一起工作吗?我猜 Reporting Services 正在尝试解决某些 IIF 处于错误状态的问题,这些错误条件将命中 NULL Finished 字段并因此导致错误?