AVG comes out rounded instead of float ??!

Results 1 to 3 of 3

Thread: AVG comes out rounded instead of float ??!

  1. #1
    T.Cohen Guest

    Default AVG comes out rounded instead of float ??!

    I&#039m using the following sql query in asp through ado :<BR><BR>RS.Open "SELECT Data.Itemnr, StDev(Data.Vraagcijfer) AS StDevOfVraagcijfer, Avg(Data.Vraagcijfer) AS AvgOfVraagcijfer, Count(Data.Vraagcijfer) AS CountOfVraagcijfer" _<BR> & " FROM Data INNER JOIN Academiejaar ON Data.Jaar = Academiejaar.Jaar" _<BR> & " GROUP BY Data.Vakcode, Data.Jaar, Data.Itemnr" _<BR> & " HAVING (((Data.Vakcode)=&#039"&vakcodeChosen&"&#039) AND ((Data.Jaar)="&jaarChosen&"))", ADOConn, adOpenStatic<BR><BR>aantalRecs = RS.recordcount<BR><BR>RS.MoveFirst<BR>Dim x<BR>do until RS.EOF <BR> for each x in rs.fields<BR> response.write(x.name)<BR> response.write(" = ")<BR> response.write(x.value & "<BR>")<BR> next<BR> Response.Write("<BR>")<BR> RS.MoveNext<BR>loop <BR><BR>Output is pretty ok, but the AVG values are rounded down (int), instead of plain floats. If i use the query in access i do get normal floats. <BR><BR>I somehow except that ADO-AVG returns INTs as soon as one record in the resultset averaged to an int.. How can i tell ado to output in floats?<BR><BR>Any ideas?<BR>

  2. #2
    Sateesh Guest

    Default RE: AVG comes out rounded instead of float ??!

    hey nothing wrong with the query, check the datatype in the database. Run the same query in the plsql window and check whether the plsql returns a float if yes try using cdbl function in the asp page, but no need to use the cdbl the ado will return the resultset as strings inspite of what ever the datatype is, so i hope the problem is with the datatype itself

  3. #3
    T.Cohen Guest

    Default RE: AVG comes out rounded instead of float ??!

    Nope, that doesn&#039t seem to do anything.<BR><BR>The original data.Vraagcijfer type is integer, and AVG&#039ing it seems to result in integers instead of double/floats. Strange because using StDev on Vraagcijfer does output floats.<BR><BR>Also using cdbl(x.value) still outputs floats (x being rs.fields). so this means that the resultset already got ints instead of floats.<BR><BR>In access using the same query and linked tables it DOES give floats (and ints where the results is an integer, 4.0 is truncated to 4).<BR><BR>Dunno why, but seems to me it&#039s a setting in ADO or something ?<BR>Also, i&#039m using SQL 2000 on Win NT4.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts