I'm having a problem with arithmetic overflow when converting to bigint in SQL Server 2008. The following is confusing me.
This works:
select 58356453 * 228204732751
Answer: 13317218761161292203
But, all other attempts that involve 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've also tried "cast(BigNumber as bigint)" (don't think it's any different from convert), and various combinations of conversion before/after arithmetic operations.
And, this is on Windows Server 2008 x64
The maxiumum value for a bigint is
9223372036854775807
you're returning
13317218761161292203.
I suggest casting to a decimal that has enough precision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With