I am getting the following error :
Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type int.
The numbers are not too big for bigint
. I am unable to point out what is going wrong here. Any pointers please.
Query
DECLARE SP bigint
DECLARE LP bigint
SET SP = 125000000
SET LP = 88300000
SELECT a = CAST((AVG(LP * 100 / CAST(SP AS DECIMAL(10, 2)))) AS DECIMAL(10,2))
@
on your variables, and it should overflow converting to numeric, not int. At least that's what happens on SQL2008. – Joe Enos Nov 26 '14 at 21:46DECIMAL(10,2)
gives you a decimal with a total of 10 digits, 2 of which after the decimal point - so 8 digits before the decimal point. BUT yourSP
value (which should be@SP
, really) has nine digits - this cannot be converted toDECIMAL(10,2)
! You need to use more digits in your decimal type, e.g.DECIMAL(16,2)
or something like that – marc_s Nov 27 '14 at 6:24