I have two numbers stored in database as decimal with precision equals to 9. My objective is to add these two numbers and update the value in database.
DECLARE @v1 DECIMAL(9, 5), @v2 DECIMAL(9, 5)
SET @v1 = 9503.34000
SET @v2 = 1357.62000
SELECT CAST(@v1 + @v2 AS DECIMAL(9, 5))
When i add this in SQL it throws overflow error however on changing it to 10,5 it results in 10860.96000 .
How can i tell SQL to add and return result based on precision i want. I want this sum to return me 9,5 NOT 10,5.
DECIMAL(9,5)
- this is a decimal number with a total of 9 digits, 5 of which are after the decimal point. That only leaves 4 digits before the decimal point, which is insufficient to hold your result.