none
AVG to return floating value

    Question

  • My have interger type field in my table and would like to calcuate the Average resut.

    I use following code.

    SELECT AVG(MyIntegerField) from MyTable

    The result always integer. The average result could be float, since it use sum of value divide by the number of items.

    I would like to know is it possible to have ACG(IntegerField) to get float result or I need specific to ask SQL return float result.

    If yes, can you please advise the sample code to do this?

    Your help and information is great appreciated,

    Regards,

    Sourises,

    Thursday, November 08, 2012 4:50 PM

Answers

  • Hi,

    Do as below

    SELECT AVG( CAST(MyIntegerField as FLOAT)) from MyTable 


    PS.Shakeer Hussain

    • Marked as answer by sourises Thursday, November 08, 2012 6:46 PM
    Thursday, November 08, 2012 4:52 PM

All replies

  • Hi,

    Do as below

    SELECT AVG( CAST(MyIntegerField as FLOAT)) from MyTable 


    PS.Shakeer Hussain

    • Marked as answer by sourises Thursday, November 08, 2012 6:46 PM
    Thursday, November 08, 2012 4:52 PM
  • Thanks a million for helping and information,

    Regards,

    Sourises,

    Thursday, November 08, 2012 6:46 PM