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
 avg

Author  Topic 

jeff06
Posting Yak Master

166 Posts

Posted - 2007-01-24 : 10:45:40
why in following sql, avg returns an integer?
I am expecting a real number.
Thanks.
Jeff


/*rpt_contractdetails almost matches the submission report*/
select datepart(yy,creationdate) as syear, datepart(Mm, creationdate) as smonth,
count(contractid) as scount,avg(rpt.CSC3Grade) as avgsc3
from rpt_contractdetails as rpt
where creationdate >='2006-01-01 00:00:00.000'
and contracttypeid=130100 and regionid=3
group by datepart(Yy,creationdate), datepart(Mm, creationdate)
order by datepart(Yy,creationdate), datepart(Mm, creationdate)

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-01-24 : 11:12:39
When you average an integer column, it returns an integer. Convert the value to a float before you average it
avg(convert,float,rpt.CSC3Grade))


CODO ERGO SUM
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-01-24 : 11:24:22
AVG(1.0 * rpt.CSC3Grade)


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

jeff06
Posting Yak Master

166 Posts

Posted - 2007-01-24 : 12:02:45
Appreciate your help.
Go to Top of Page
   

- Advertisement -