I'm trying to add a numeric(16,8) to a smalldatetime. I receive an overflow error which I cannot make sense of.
metric_value is the number, business_date is the smalldatetime.
SELECT
rsda.name
, business_date
, metric_value
, DATEADD(dd, metric_value, business_date) AS o_dt
, metric.name
FROM [redacted] met
INNER JOIN [redacted] rsda ON met.bu_id = rsda.data_accessor_id
INNER JOIN Metric ON met.metric_id = metric.metric_id
WHERE CHARINDEX('Remodel', metric.name) > 0
Msg 517, Level 16, State 2, Line 1
Adding a value to a 'smalldatetime' column caused an overflow.
I realize that the obvious answer is "One of your dates adds beyond year 9999" but that isn't the case here. All of the dates are in 2017, and all of the numbers are whole numbers below 100, at least when the WHERE clause is true.
The met table has tons of other unrelated data to my 'Remodel' criteria and I'm wondering if that could cause the error. It is a strange table but I do not have control over its design. Is it possible that part of the DATEADD process occurs before my WHERE clause is applied? I cannot imagine what else is going on.
Edit. When i remove the DATEADD field:
Here's the first row of 'ORDER BY business_date ASC'
+----------+---------------------+--------------+-------------+
| name | business_date | metric_value | name |
+----------+---------------------+--------------+-------------+
| 466 - 94 | 2017-03-13 00:00:00 | 59.00000000 | FullRemodel |
+----------+---------------------+--------------+-------------+
ORDER BY business_date DESC
+----------+---------------------+-------------+-------------+
| 440 - 87 | 2017-07-31 00:00:00 | 38.00000000 | FullRemodel |
+----------+---------------------+-------------+-------------+
ORDER BY metric_value ASC
+----------+---------------------+------------+----------------+
| 471 - 05 | 2017-05-01 00:00:00 | 0.00000000 | PartialRemodel |
+----------+---------------------+------------+----------------+
ORDER BY metric_value DESC
+----------+---------------------+-------------+-------------+
| 466 - 86 | 2017-03-13 00:00:00 | 59.00000000 | FullRemodel |
+----------+---------------------+-------------+-------------+