在MSDN中明确表示:
The date argument cannot be incremented to a value outside the range of its data type. In the following statements,the number value that is added to the date value exceeds the range of the date data type. The following error message is returned: “Adding a value to a ‘datetime’ column caused overflow.”
这个例子:
SELECT DATEADD(year,2147483647,'2006-07-31'); SELECT DATEADD(year,-2147483647,'2006-07-31');
这会导致错误:
“Adding a value to a ‘datetime’ column caused overflow.”
这似乎是对的.但是为什么我在执行这个sql语句时遇到同样的错误:
SELECT DATEDIFF(YY,'1013-12-12',DATEADD(YY,-300,getdate()))
更具体,唯一:
SELECT DATEADD(YY,getdate())
解决方法
First google result for ‘sql datetime range’年1月1日,1753年.那是你的下限.
关于这个问题的评论增加了this trivia关于这个下界的起源.