sql - Arithmetic overflow error converting nvarchar to data type numeric when creating string -
trying figure out why getting error happens when creating string exec
set @sqlinsertstringfinal = @sqlinsertstring + @suggested_qty+''','''+ @required_qty+''','''+ @system_cost+''','''+ @revised_cost
these 4 variables populated
convert(numeric(7,2),ltrim(rtrim(floor((case when r.calc_qty > 99999 99999 else r.calc_qty end)/(case when s.plbcf_1 null or s.plbcf_1 =0 1 else s.plbcf_1 end))))), convert(numeric(7,2),ltrim(rtrim(floor((case when r.po_number <> 'none' r.calc_qty else case when r.adj_qty > 99999 99999 else r.adj_qty end end)/(case when s.plbcf_1 null or s.plbcf_1 = 0 1 else s.plbcf_1 end))))), convert(numeric(9,4),ltrim(rtrim(case when s.std_cost null r.std_cost else s.std_cost end))), convert(numeric(9,4),ltrim(rtrim(r.std_cost)))
i've check every table used , consistent in column type. non numeric in there r.po_number can of value 'none'
you need convert each numeric string when you're setting final string value this:
set @sqlinsertstringfinal = @sqlinsertstring + convert(nvarchar(max), @suggested_qty)+''','''+ convert(nvarchar(max), @required_qty)+''','''+ convert(nvarchar(max), @system_cost)+''','''+ convert(nvarchar(max), @revised_cost)
it won't auto-cast you
Comments
Post a Comment