Is there any difference between the following statements?
SELECT DATEADD(MONTH, @SomeInteger * 12, @SomeDate)
SELECT DATEADD(YEAR, @SomeInteger, @SomeDate)
In other words, are there any cases in which they would yield different results for the same value of @SomeInteger
and @SomeDate
?
I ran a quick test via the following:
SELECT
*
FROM dbo.DimDate dd
WHERE DATEADD(MONTH, 12, dd.Date) <> DATEADD(YEAR, 1, dd.Date)
which returned zero records, but that's far from proving the two statements are equivalent.
The computer scalar
execution plan component has the exact same cost in both queries, but the ScalarOperator
definitions are different - it would appear that the Query Optimizer is not converting one statement into another.
Thanks!