• I too am having the same problem. Creating a sum of a time spent numeric field from a support ticket database. The data shows correctly if you view the #aggregates table. When you run the query for #rows, it removes the decimal point and everything after. ( 214.50 becomes 214). When declaring the datatype as MONEY, the final resultset rounds the value.

    It looks like there is something happening in the exec (@sql) command.

    Great code though...will save a ton of time!

    UPDATE: This line:

    SELECT @SQL = 'ALTER TABLE #ROWS ADD ' + QUOTENAME(@COLUMNTEXT) + ' INT DEFAULT 0'

    is what changes the datatype for the CellData. I've corrected by changing it to:

    SELECT @SQL = 'ALTER TABLE #ROWS ADD ' + QUOTENAME(@COLUMNTEXT) + ' NUMERIC(19,2) DEFAULT 0'