最近我正在玩SQL Server数据类型,并将大量数据放入表中,并尝试用Varchar和Numeric数据计算性能。但是,我得到了一些错误,这是我不认为不应该,但它是。我的问题是如下:具有Int和Decimal转换功能的Sql Server SUM函数
我有一个表:
create table sa(f1 varchar(100))
我有一个存储过程,而插入100000个数据到表:
create proc sad
as
begin
declare @i int=0
while @i<100000
begin
insert into sa values(@i)
set @[email protected]+1
end
end
exec sad
而且我已经测试了以下内容:
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
但是,当我总结转换F1到INT,它显示我一个错误。
但是,当我只选择转换为Int罚款。
而且,当我总结转换F1到十进制它工作正常。
什么是SUM函数的数据类型?
在上面的数据它适用于十进制,但不是诠释?
为什么?
即时得到以下错误
算术溢出错误将表达式转换为数据类型int。
请复制并粘贴您收到的错误... –
对不起,我编辑了我的问题,并收到了错误 –
我试图找出性能问题,同时使用Varchar和数字数据类型 –