December 12, 2008 at 4:13 am
Dear All,
While i executing
select 1545801376+1833558419
i got the error "Arithmetic overflow error converting expression to data type int."
But at the same time if i execute this
select 2545801376+2833558419
i got the result 5379359795
Why this has happened?
Thanks and Regards,
N.Prabhakaran
December 12, 2008 at 4:24 am
In the first statement, both of those numbers are integers. When SQL does maths on two integers, the result will be an int. In this case, the result is too big for an int and there's an overflow.
In the second one, one of the numbers is a bigint. Hence SQL converts the other to a big int as well and does the maths on two bigints, producing a result that's a bigint.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
December 12, 2008 at 5:15 am
I did not know this.... I tried with some statements ... its really great to understand this.
Just try with these statements and post your comments.
select 5+2147483647
select 2545801376+2833558419
select 7758079223372036854775807+7758079223372036854775807
select 7758079223372036854775807+1
Just run those statements and check how it behaves.....
its really nice to see the behavior.
After working for some minutes I came to know why its behaving like that.... you also try & see.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply