DECLARE @i INT
SET @i=14
SELECT COALESCE(@i, GetDate());
以上返回
1900-01-15 00:00:00.000
现在,如果我将i更改为11,结果将是
1900-01-12 00:00:00.000
GETDATE()不应该返回当前日期时间吗?
答案 0 :(得分:2)
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,因为coalesce的第二个参数是datetime