Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arithmetic overflow error converting expression to data type smallint

I am new to SQL Server, this question might be repeated here. Since i haven't find a solution for my problem. I wished to post here. So here is my problem

select(volume * speed)  from traffic_data_replica;

I am trying to multiply values from two columns , data type is smallint for both columns. Error i got is :

Msg 8115, Level 16, State 2, Line 1
Arithmetic overflow error converting expression to data type smallint.

like image 579
bibinmatthew Avatar asked Nov 03 '25 04:11

bibinmatthew


1 Answers

Cast one of the values to a "bigger" type before the calculation:

select cast(volume as int) * speed
from traffic_data_replica;

You can also do this easily by multiplying by 1.0:

select 1.0*volume*speed
from  traffic_data_replica
like image 129
Gordon Linoff Avatar answered Nov 04 '25 18:11

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!