在 SQL 服务器中与 COALESCE 一起使用时 GETDATE() 的奇怪行为
Strange behavior of GETDATE() when used with COALESCE in SQL SERVER
DECLARE @i INT
SET @i=14
SELECT COALESCE(@i, GetDate());
超过 returns
1900-01-15 00:00:00.000
现在如果我将 i 更改为 11,结果将是
1900-01-12 00:00:00.000
不应该 GETDATE() return 当前日期时间?
When an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence.
1900-01-01 + 14 是 1900-01-15,你的 int 被转换为 datetime,因为合并的第二个参数是 datetime
DECLARE @i INT
SET @i=14
SELECT COALESCE(@i, GetDate());
超过 returns
1900-01-15 00:00:00.000
现在如果我将 i 更改为 11,结果将是
1900-01-12 00:00:00.000
不应该 GETDATE() return 当前日期时间?
When an operator combines two expressions of different data types, the rules for data type precedence specify that the data type with the lower precedence is converted to the data type with the higher precedence.
1900-01-01 + 14 是 1900-01-15,你的 int 被转换为 datetime,因为合并的第二个参数是 datetime