Arithmetic overflow w / bigints in SQL Server 2008

I had an arithmetic overflow problem when converting to bigint in SQL Server 2008. The following is confusing to me.

It works:

select 58356453 * 228204732751 

Answer: 13317218761161292203

But all other attempts involving explicit conversion fail.

 select convert(bigint, 58356453 * 228204732751) 

result: arithmetic overflow

 begin declare @key bigint = 58356453, @workingVal bigint, @primeMultiplier1 bigint = 228204732751; set @workingVal = @key * @primeMultiplier1; end; 

result: arithmetic overflow

What am I missing here? I also tried "cast (BigNumber as bigint)" (I don’t think it is different from conversion) and various combinations of conversion before / after arithmetic operations.

And this is on Windows Server 2008 x64

+6
sql-server sql-server-2008
source share
2 answers

Maximum value for bigint

9223372036854775807

you are coming back

13317218761161292203.

I propose to distinguish a decimal digit that has sufficient accuracy.

+2
source share

You must use a numeric data type .

 select cast(13317218761161292203 as numeric(38)) 
0
source share

All Articles