如果在SQL Server 2014中运行以下查询,您会得到DT列的结果?它应该是“1”,但在SQL Server 2008中,我得到“0”。
SELECT
CASE WHEN CAST('2014-01-02 00:00:00.001' AS DATETIME) > CAST('2014-01-02 00:00:00.000' AS DATETIME) THEN 1 ELSE 0 END AS 'DT'
, CASE WHEN CAST('2014-01-02 00:00:00.002' AS DATETIME) > CAST('2014-01-02 00:00:00.000' AS DATETIME) THEN 1 ELSE 0 END AS 'DT2'
, CASE WHEN '2014-01-02 00:00:00.001' > '2014-01-02 00:00:00.000' THEN 1 ELSE 0 END AS 'VARCHAR'
答案 0 :(得分:4)
日期时间字段的分辨率为 3个小数位。只能在3.33毫秒内准确
SQL Server将'2014-01-02 00:00:00.001'
和'2014-01-02 00:00:00.000'
都视为2014-01-02 00:00:00.000
。
SELECT Cast('2014-01-02 00:00:00.001' AS DATETIME),
Cast('2014-01-02 00:00:00.000' AS DATETIME)
两个日期的结果相同。
在你的案例陈述中CAST('2014-01-02 00:00:00.001' AS DATETIME) > CAST('2014-01-02 00:00:00.000' AS DATETIME)
失败了,因为两者都是相同的,所以其他部分0
都有效。