February 12, 2014 at 4:42 am
Hi,
I'm using this query to sum the values. The cost column is a float datatype and what could I differently do here to sum the cost. I'm unable to sum the cost.
Also is there any way I change the datatype to int for Cost column without losing the data.
select ID, MAX(Date) Date, SUM(Cost) Cost, MAX(Funding) Funding from Appllication
group by ID
February 12, 2014 at 9:51 am
Why can't you sum a float column? float is a numeric data type and it can be used in SUM().
Here's what I used to test.
DECLARE @Appllication TABLE(
IDint,
Datedate,
Costfloat,
Fundingfloat
)
INSERT INTO @Appllication
VALUES
(1,'20140201', 10.52, 5),
(1,'20140202', 20, 15),
(3,'20140205', 30.1245, 50),
(3,'20140201', 110, 5)
select ID, MAX(Date) Date, SUM(Cost) Cost, MAX(Funding) Funding from @Appllication
group by ID
February 12, 2014 at 10:05 am
i would mention something here,
be cautious when you work with real number, because there is a little bit difference in result when you sum float, decimal or money data type.
In the case of precision, you have to rely on a existing result and to work with appropriate data type
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply