SQL Server Reporting Services 将小时格式设置为小时:分钟
我正在 SQL Server Reporting Server 上编写报告,其中包含按用户分组的小时数以及根据值总和计算的总计。
目前,我的查询运行一个存储过程,它以 HH:MM 格式返回小时,而不是十进制小时,因为我们的用户发现这更直观。当我尝试使用 SSRS 表达式对列进行求和时,就会出现问题,因为 SUM 函数不够智能,无法处理这种格式的求和时间。
有没有办法:
- 以 HH:MM 格式显示时间间隔(以分钟或小时为单位),同时以十进制形式计算?
- 或者拆分并计算 HH:MM 文本值的总和以得出表达式形式的总和?
我想避免仅仅为了获得总数而编写/运行第二个查询。
I'm writing reports on SQL Server Reporting Server that have a number of hours grouped by, say, user, and a total calculated based on the sum of the values.
Currently my query runs a stored proc that returns the hours as in HH:MM format, rather than decimal hours, as our users find that more intuitive. The problem occurs when I try and add up the column using an SSRS expression, because the SUM function isn't smart enough to handle adding up times in this format.
Is there any way to:
- Display a time interval (in minutes or hours) in HH:MM format while having it calculated in decimal form?
- Or split up and calculate the total of the HH:MM text values to arrive at a total as an expression?
I'd like to avoid having to write/run a second query just to get the total.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
回答我自己的#1:
TimeSpent
表示)。=FLOOR(Fields!TimeSpent.Value / 60) & “:”& RIGHT("0" & (Fields!TimeSpent.Value MOD 60), 2)
=FLOOR(Sum(Fields!TimeSpent.Value) / 60) & “:”& RIGHT("0" & (Sum(Fields!TimeSpent.Value) MOD 60), 2)
Answering my own #1:
TimeSpent
below).=FLOOR(Fields!TimeSpent.Value / 60) & ":" & RIGHT("0" & (Fields!TimeSpent.Value MOD 60), 2)
=FLOOR(Sum(Fields!TimeSpent.Value) / 60) & ":" & RIGHT("0" & (Sum(Fields!TimeSpent.Value) MOD 60), 2)
您也可以尝试将此函数放入报告的自定义代码中。
我的 SP 通常以秒为单位返回时间,如果我必须在多个地方返回 HH:MM:SS,这使我不必费力思考。另外,您可以正常执行所有聚合并将它们包装在其中以获得漂亮的格式。
我不能将此归功于我,因为我知道我不久前在网上偶然发现了它,但我不记得在哪里。
You may also try putting this function in your report's custom code.
My SPs generally return time in seconds and this keeps me from having to think too hard if I have to return HH:MM:SS in more than one place. Plus, you can do all of your aggregations normally and wrap them in this to get a pretty format.
I can't take credit for this as I know I stumbled across it on the web some time ago, but I can't recall where.
因此,在您的情况下,它是分钟,因此您需要将其转换为秒,您可以尝试使用以下代码:
=Format(DateAdd("s",(Parameters!ReportParameter1.Value * 60), "00:00:00"), “HH:mm:ss”)
希望这有帮助
So in your case its minutes so you need to convert it to seconds , you can try using below code:
=Format(DateAdd("s",(Parameters!ReportParameter1.Value * 60), "00:00:00"),"HH:mm:ss")
Hope this helps