【发布时间】:2015-07-20 22:15:12
【问题描述】:
需要在 Reporting Services 报告中根据以下逻辑显示日期范围,如下所示:
如果只有 Started 日期时间,则显示如下:
2014 年 12 月 12 日
如果同一天有 Started 和 Finished 日期时间,显示如下:
2014 年 12 月 12 日上午 11:20 至下午 1:10
如果有不同日期的开始和结束日期时间,显示如下:
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 为 null,那么我总是会得到 #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 为 null 时一切正常。
知道为什么我不能让丑陋的声明的两个部分一起工作吗?我猜 Reporting Services 正在尝试解决一些 IIF 在错误条件下的问题,这些错误条件将命中 NULL Finished 字段并因此导致错误?
【问题讨论】:
-
我猜 Reporting Services 正在尝试解决一些 IIF 在错误条件下的问题,这些错误条件将命中 NULL Finished 字段并因此导致错误? => 你的猜测是对的
标签: reporting-services vbscript ssrs-2012 ssrs-expression