从sql server中的小计小时计算总小时数 [英] calculating total hours from subtotal hours in sql server

查看:257
本文介绍了从sql server中的小计小时计算总小时数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

我正在尝试从sql server 2008 R2中每个员工的小计小时计算所有员工的总小时数。如果小计低于24:00格式,它可以正常工作。我正在使用这个查询



select @ grossHrs = CAST((SUM(datepart(hh,convert(varchar,GrossHours,108)))+(sum(datepart( mi,convert(varchar,GrossHours,108)))/ 60))AS VARCHAR(5))+':'+ RIGHT('00'+ CAST(sum(datepart(mi,convert(varchar,GrossHours,108)) ) - 60 *(总和(datepart(mi,convert(varchar,GrossHours,108)))/ 60)as VARCHAR(5)),2)

来自#temp



如果小计时间超过24:00,请帮助我

解决方案

这是我的建议。

将所有总小时数转换为分钟。



运行查询以将这些转换的分钟相加,然后除以60得到总小时数。

Hi friends,
I am trying to calculate total hours of all employees from subtotal hours of each employee in sql server 2008 R2. It is working if the subtotals are below 24:00 format. i am using this query

select @grossHrs=CAST((SUM (datepart(hh, convert (varchar, GrossHours, 108))) +(sum(datepart(mi, convert (varchar, GrossHours, 108)))/60))AS VARCHAR(5))+ ':' +RIGHT('00'+ CAST( sum(datepart(mi, convert (varchar, GrossHours, 108))) - 60 * (sum(datepart(mi, convert (varchar, GrossHours, 108)))/60)as VARCHAR(5)),2)
from #temp

Can u please help me if subtotal hours are more than 24:00

解决方案

Here is my recommendation.
Convert all gross hours to minutes.

Run a query to sum these converted minutes and then divide by 60 to get the total number of hours.


这篇关于从sql server中的小计小时计算总小时数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆