在MSDN
清楚地表示:「向'datetime'列添加值導致溢出。」
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())
最小'datetime'是1753 [因爲那是英國採用公曆之後的一年](http://stackoverflow.com/questions/3310569/what-is-the-significance-of-1-1- 1753-in-sql-server/3310588)你在什麼版本的SQL Server上? – 2012-02-22 19:33:42
@Joro - Well'SELECT DATEADD(YY,-300,cast(getdate()as datetime2))'然後就可以爲你工作。 – 2012-02-22 21:08:12
@MartinSmith是的,你是對的。我檢查過這個,'datetime2'和'datetimeoffset'格式的支持日期從1,0001年1月到9999年12月31日。SQL語句到現在爲止是否意味着getdate()函數的默認類型是'datetime'據說'datetime'和'smalldatetime'折舊。 – gotqn 2012-02-26 11:52:32