How do I convert to a percentage?

  • Hi,

    I'm trying to do some math, then convert the results to a percentage, but I come up with 0. Here's the select:

    select CONVERT(varchar,((76075/119027) *100)) + ' %' from master.sys.databases where database_id=1

    The above should show me 63.91%, but instead I get 0 %.

    Thanks!

  • You need to use decimal math, instead of integer math.

    select

    Wrong = (76075/119027)*100 ,

    Correct = (76075./119027.)*100.

    Results:

    Wrong Correct

    ----------- ------------------

    0 63.9140600

  • Perfect, thank you!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply