I am trying to create the following view:
CREATE VIEW [dbo].[_TEST]
AS
SELECT
a.[PS],
b.[A0001],
CAST(a.[Area] AS DECIMAL(15, 10)) AS A0002,
CAST((b.[0001] / a.[Area]) AS DECIMAL(15, 10)) AS A0003
FROM
dbo.Areas AS a
INNER JOIN
(SELECT
LEFT(PSOA, 6) AS PS, SUM([0001]) as A0001
FROM
dbo.Counts
GROUP BY
LEFT(PSOA, 6) AS b ON a.PS = b.PS
The view creates fine but I get the error below when using it:
Arithmetic overflow error converting numeric data type to numeric
Now, from my understanding, that means the values are too big to fit into a Decimal(15,10). However, manually calculating them, the biggest value I get for A0003 is 2151.93382, which is fine for a Decimal(15,10). I even tried Decimal(20,10) just to be sure and that returns the same error. The figures are definitely not too big, so what's going wrong?
However, manually calculating them... don't manually calculate anything. Do aSELECT MAX(value)from your table and see what the largest value actually is. - Tim Biegeleisen