当duration为float类型时,sql server中的时间总和

时间:2018-03-08 06:46:07

标签: sql-server time sum

select dbo.to_hour(SUM(6666.008888))

上面的select语句给出的持续时间为-* h 6m(to_hour函数只接受int但我的duration列是FLOAT数据类型。)

但我想要time as -111h 1m

请告诉他们如何转换它

1 个答案:

答案 0 :(得分:1)

试试这个答案:

SELECT LEFT(CAST((6666.008888)/60 AS VARCHAR),CHARINDEX('.',CAST((6666.008888)/60 AS VARCHAR))-1) + 'h'
    +' '+SUBSTRING(CAST((6666.008888)/60 AS VARCHAR),CHARINDEX('.',CAST((6666.008888)/60 AS VARCHAR))+1,1) + 'm'

<强> OR

DECLARE @Value NUMERIC(15,8)=6666.008888

SELECT LEFT(CAST((@Value)/60 AS VARCHAR),CHARINDEX('.',CAST((@Value)/60 AS VARCHAR))-1) + 'h'
    +' '+SUBSTRING(CAST((@Value)/60 AS VARCHAR),CHARINDEX('.',CAST((@Value)/60 AS VARCHAR))+1,1) + 'm'

<强>输出:

111h 1m