Forum Discussion

ak105's avatar
ak105
Frequent Visitor
4 years ago
Solved

odata pull - calculations not pulling correctly

Hello all,    I have been pulling data via odata and been trying to calculate percentages within my query The code is as follows: &"aggregate(" &"$count as TotalCount," &"cast(LastResultOutc...
  • v-jingzhang's avatar
    4 years ago

    Hi ak105 

     

    The results are correct because both dividend and divisor are Integers. When you use div or /, it returns the data type of the argument with the higher precedence. For more information, see Data Type Precedence (Transact-SQL)If an integer dividend is divided by an integer divisor, the result is an integer that has any fractional part of the result truncated. Reference: / (Division) (Transact-SQL)

     

    To have the percentage fields return decimal numbers, you can convert the dividends or divisors to float or decimal data types. 

    Data type conversion (Database Engine) 

    CAST and CONVERT (Transact-SQL) 

     

    Best Regards,
    Community Support Team _ Jing
    If this post helps, please Accept it as Solution to help other members find it.