SQL Server 2008 R2 SP1
SELECT
VEN.EAN11ZUC AS EAN
, SUM(DET.NbMag) --<< when this line is commented, no error!!!
FROM ODS_Vente VEN
inner join ODS_DetentionCentraleArticle DET
on VEN.EAN11ZUC = DET.EANZUC
group by VEN.EAN11ZUC
实际输出:
“消息8115,将数值转换为数据类型的算术溢出错误 数字“
答案 0 :(得分:1)
我的猜测是总和不能与源字段的数字精度/比例相同。您可以尝试将原始值转换为最大可能的精度:
SELECT
VEN.EAN11ZUC AS EAN
, SUM(CAST DET.NbMag AS NUMERIC(38,{# of decimals you want to support}) )
FROM ODS_Vente VEN
inner join ODS_DetentionCentraleArticle DET
on VEN.EAN11ZUC = DET.EANZUC
group by VEN.EAN11ZUC