T-SQL中的舍入毫秒数 [英] Rounding milliseconds in T-SQL
本文介绍了T-SQL中的舍入毫秒数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 SQL Server 2008
中,我在表中列出了 DateTime
类型的列。
In SQL Server 2008
, I have the below column of type DateTime
in a table.
+-------------------------+
| LTime |
+-------------------------+
| 2009-12-07 10:40:21.893 |
| 2009-12-07 10:42:18.173 |
+-------------------------+
从上面的列中,我想选择 datetime
并舍弃 milliseconds
,以获得以下输出
From the above column, I want to select the datetime
and round off the milliseconds
, in order to get the below output
+---------------------+
| LTime |
+---------------------+
| 2009-12-07 10:40:22 |
| 2009-12-07 10:42:18 |
+---------------------+
非常感谢您的帮助。
推荐答案
SELECT CAST('2009-12-07 10:40:21.893' AS DATETIME2(0)),
CAST('2009-12-07 10:42:18.173' AS DATETIME2(0))
做你所需要的
这篇关于T-SQL中的舍入毫秒数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文