Recently i was Playing with SQL Server data types, and Large number of data into the table and trying to figure-out the Performance with Varchar and Numeric data. But, i got some error which is i dont think should not have to be but it is. My problem is below :
I have a table :
create table sa(f1 varchar(100))
I have a Stored Procedure which Inserts 100000 data into the table :
create proc sad
as
begin
declare @i int=0
while @i<100000
begin
insert into sa values(@i)
set @i=@i+1
end
end
exec sad
And I have tested the following with :
select CONVERT(int,f1) from sa //Works Fine, i tested after the Problem
select sum(convert(int,f1)) from sa //Didn't Worked, So i tested above and Below
select sum(convert(decimal(18,2),f1)) from sa //And, it again works fine
But, When i sum Converting F1 to Int, it shows me an error.
But, when i only select Converting to Int its fine.
And, when i sum Converting F1 to decimal it works Fine.
What the SUM function data type?
On the Above data it works well with Decimal but not Int?
Why?
Im Getting the Following error
Arithmetic overflow error converting expression to data type int.