获取sql server 2008中的时间总和

时间:2012-09-05 05:34:47

标签: sql-server-2008

我有一个表tblTimesheet,其中我存储用户计时hr。像这样

Hours
4.01
3.44
0.05
0.04
2.40

我想要的是我正在使用此

的部分时间段
select sum(hours) from tbltimesheets where workDate='2012-08-30 00:00:00.000' and taskid in (86,3,34)

但它给了我9.94,我希望得到10.34这个字段的数据类型是十进制

请帮帮我

提前致谢

2 个答案:

答案 0 :(得分:1)

这样的东西
DECLARE @Table TABLE(
        Hrs FLOAT
)
INSERT INTO @Table SELECT 4.01 
INSERT INTO @Table SELECT 3.44 
INSERT INTO @Table SELECT 0.05 
INSERT INTO @Table SELECT 0.04 
INSERT INTO @Table SELECT 2.40

;WITH Vals AS (
        SELECT  SUM(FLOOR(Hrs)) NumHrs,
                SUM((Hrs - FLOOR(Hrs)) * 100) NumMins 
        FROM    @Table
)
SELECT  NumHrs + FLOOR(NumMins / 60) + ((NumMins / 60 - FLOOR(NumMins / 60)) * 60 / 100)
FROM    Vals

答案 1 :(得分:0)

 first hours conet to minute and last step divide by 60.
select (sum(hours*60)/60) from tbltimesheets where workDate='2012-08-30 00:00:00.000' and taskid in (86,3,34)