我有一个客户希望根据他们的报告显示报告的执行时间。为了适应它们,我在报告(在报告属性下)创建了一个名为“GroupExecutionTime”的变量,其表达式如下:
=System.DateTime.Now
然后在报告的页脚中,我有以下内容:
="Execution Time: " +
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).TotalSeconds < 1, "0 seconds",
(
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours & " hour(s), ", "") +
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes & " minute(s), ", "") +
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds & " second(s)", ""))
)
不幸的是,客户回来说他们希望我显示报告执行的毫秒数,而它不到一秒。这是一个低优先级的要求,但好奇心和满足要求的愿望让我想知道这是如何完成的?不幸的是System.DateTime.Now
,似乎没有存储任何低于秒的东西。
修复了以下问题(感谢 Anthony Sottile 的回答)
="Execution Time: " +
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).TotalSeconds < 1, "0." & Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Milliseconds & " seconds.",
(
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Hours & " hour(s), ", "") +
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Minutes & " minute(s), ", "") +
IIf(Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds > 0, Variables!GroupExecutionTime.Value.Subtract(Globals!ExecutionTime).Seconds & " second(s)", ""))
)