Chakki
Chakki

Reputation: 21

Multiplication issue in sql server 2012

when I trying to multiply two 6 digit numbers I got an error like this 'Arithmetic overflow error converting expression to data type int'. am alredy trying with numeric format. but I got the same issue.

eg: select ( 4561 * 6541)

Please give me a proper solution for this. Waiting for a good solution.

Upvotes: 1

Views: 128

Answers (3)

Chakki
Chakki

Reputation: 21

I got the solution, select cast(234561 as numeric(10,0)) * cast(622541 as numeric(10,0))

Upvotes: 0

knkarthick24
knkarthick24

Reputation: 3216

Integer variable capable of storing values only between -2,147,483,648 and 2,147,483,647.

In your case, you are trying to multiply two six digit numbers which is (123456 * 123456) = 15241383936 (no where falls between the Integer Limit). So that's why you should go for BIGINT datatype using SQL Server CAST or CONVERT function. Always search for MSDN.

Upvotes: 0

komodosp
komodosp

Reputation: 3618

Cast to bigint

select cast(234561 as bigint) * cast(622541 as bigint)

(Note your 4 digit numbers in the example worked fine for me but got the error with 6 digit numbers as you described which was resolved by the code above)

Upvotes: 2

Related Questions