I set up a new etl job in SSIS. The currency fields are all defined as decimal(17,2)
data type. When the results are exported to excel, those fields appear to have extended decimals beyond 2. It does not visually exist in the fields, but when you do a sum of the column they show up in the result. The data used to populate those currency fields have the same data type, but I am storing the records as a summary, not at the transaction level. I initially thought this was an excel problem, so I ran a test in sql and came up with unexpected results.
How is it possible if sql is only storing 2 decimal places, to output 10+ decimal places from a sum function? I tried to do some research on this and I didn't find anything.
I have so-so corrected the results by doing a cast(round(myvalue,3) as decimal(17,2)). there are still extended decimal places in my output, but it is small enough that it doesn't cause a balancing issue.
-----------multiple records----------------
create table #MyPi (MyPi decimal(17,2))
Declare @mycounter int
set @mycounter =1
while @mycounter <> 500000
begin
insert into #MyPi(Mypi)
values (round(3.14159,3))
set @mycounter = @myCounter +1
end
-------------Single Record----------------
create table #MyPi2 (MyPi decimal(17,2))
insert into #MyPi2(Mypi)
values (3.14159)
Results of my test (500k records)
select sum(Mypi) SumMyPi, sum(cast(Mypi as float))SumMyPiAsFloat from #MyPi
SumMyPi SumMyPiAsFloat
1569996.86 1569996.85998705
1 record
select Mypi, cast(Mypi as float) MypiAsFloat from #MyPi2
Mypi MypiAsFloat
3.14 3.14