4

我有一个客户希望根据他们的报告显示报告的执行时间。为了适应它们,我在报告(在报告属性下)创建了一个名为“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)", ""))
)
4

1 回答 1

5

该方法生成的TimeSpan对象.Subtract()应该具有.Milliseconds可以打印的属性。

http://msdn.microsoft.com/en-US/library/system.timespan.milliseconds%28v=vs.90%29

我不确定为什么 DateTime.Now 不会记录毫秒?如果没有,那么这将没有多大帮助。不幸的是,我似乎无法启动我的 SSRS 实例来自己测试它......

于 2012-06-04T03:21:08.337 回答