W MSDN
jest wyraźnie powiedziane, że:"Dodanie wartości do kolumny" datetime "spowodowało przepełnienie."
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."
A przykład:
SELECT DATEADD(year,2147483647, '2006-07-31');
SELECT DATEADD(year,-2147483647, '2006-07-31');
który powoduje błąd:
"Adding a value to a 'datetime' column caused overflow."
to wydaje się słuszne. Ale dlaczego mam ten sam błąd wykonaniu tej instrukcji SQL:
SELECT DATEDIFF(YY,'1013-12-12',DATEADD(YY,-300,getdate()))
bardziej konkretne i tylko:
SELECT DATEADD(YY,-300,getdate())
Minimalna wartość "datetime" to 1753 [ponieważ był to rok po przyjęciu przez Wielką Brytanię kalendarza gregoriańskiego] (http://stackoverflow.com/questions/3310569/what-is-the-shnificance--1-1- 1753-in-sql-server/3310588 # 3310588) Jaką wersję programu SQL Server używasz? –
@Joro - Cóż 'SELECT DATEADD (YY, -300, rzutowanie (getdate() jako datetime2)) będzie wtedy działać. –
@MartinSmith Tak, masz rację. Sprawdziłem daty obsługi formatu "datetime2" i "datetimeoffset" od 1 stycznia 0101 do 31 grudnia 1999. Czy instrukcje SQL do tej pory oznaczają, że domyślny typ funkcji getdate() to "datetime" i dlaczego mówi się, że "datetime" i "smalldatetime" są amortyzowane. – gotqn