Reporting Services レポートでは、次のようなロジックに基づいて日付範囲を表示する必要があります。
開始日時しかない場合は、次のように表示します。
2014 年 12 月 12 日
開始日時と終了日時が同じ日にある場合は、次のように表示します。
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 の両方が null でない場合、すべてが正常に機能します。ただし、Finished が null の場合、常に #Error が発生します。
ここで、ネストされた IIf ロジックを含む IIF の 2 番目の部分を削除すると、たとえば
=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 フィールドにヒットし、エラーが発生する false 状態にあると思いますか?