Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Sum float datatype column

Author  Topic 

vignesht50
Yak Posting Veteran

82 Posts

Posted - 2014-02-12 : 06:49:20
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

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-12 : 07:35:53
why cant you sum float field?
if you want to cast it to int you'll have to round it to nearest whole number so answer would be approximate.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

vignesht50
Yak Posting Veteran

82 Posts

Posted - 2014-02-12 : 07:42:51
quote:
Originally posted by visakh16

why cant you sum float field?
if you want to cast it to int you'll have to round it to nearest whole number so answer would be approximate.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs



I changed the datatype to int. But now when I run the query It says invalid column name for cost.

Table Schema:

CREATE TABLE [dbo].[Application](
[ID] [int] NOT NULL,
[Date] [date] NULL,
[ Cost] [int] NULL,
[Funding] [varchar](5) NOT NULL
) ON [PRIMARY]

GO

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-02-12 : 08:32:32
can you post your used query?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

vignesht50
Yak Posting Veteran

82 Posts

Posted - 2014-02-12 : 08:58:57
I got it Visakh. It because I has space before the cost column and I removed it.
Go to Top of Page
   

- Advertisement -