0
我需要创建一个存储大于24小时的列。例如'25:00:00'
,'129:23:12'
等)。在SQL Server 2005中计算大约24小时以上
该列将用于执行datetime
区间间的计算:'时间'。
我试图
SELECT CAST((CAST(CAST(RIGHT('107:37', 6) as datetime) AS FLOAT))/(207.160) AS DATETIME)
如果
低于'23:59'
而不是'107:37'
工作的罚款。
'107:37'
给予错误:
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
这很愚蠢。如果你想计算时间或日期间隔,那么为什么不使用日期时间类型,时间和日期函数呢? – paulsm4 2012-04-24 07:06:58
只存储秒数会不会更简单?转换为小时和分钟是简单的算术。 – Joni 2012-04-24 07:07:51
不,将数字存储为日期时间会更简单,并使用诸如datediff()之类的函数。例如:http://stackoverflow.com/questions/1770594/how-to-calculate-difference-in-hours-decimal-between-two-dates-in-sql-server – paulsm4 2012-04-24 07:09:32