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.
| 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 avgsc3from rpt_contractdetails as rptwhere creationdate >='2006-01-01 00:00:00.000' and contracttypeid=130100 and regionid=3group 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 itavg(convert,float,rpt.CSC3Grade)) CODO ERGO SUM |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-24 : 11:24:22
|
| AVG(1.0 * rpt.CSC3Grade)Peter LarssonHelsingborg, Sweden |
 |
|
|
jeff06
Posting Yak Master
166 Posts |
Posted - 2007-01-24 : 12:02:45
|
| Appreciate your help. |
 |
|
|
|
|
|
|
|