在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,-300,getdate())