Calculating percentages

  • Be careful though ... the majority of this post used 'imlpicit' conversions. Experience has taught that 'implicit' (like 'default') can get you into trouble when you least expect it. Just because SQL is a higher level language does not mean we have to forget about basic data type compatibilities, converting to the same type or casting.

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

  • Good point... I'll try to see to it .

  • Guys, this is 7th grade math, not SQL specific.

  • .0 forces real calculation.

    If you need float precision type .00000.

    And finally, use variables. Do you actually remember what they told you on programmers courses?

    _____________
    Code for TallyGenerator

  • If you are trying to get what percentage is 426 out of 852 then

    Try this out..

    select (426 + .0)/ (852) * 100

    Result

    50.000

    Don't tell me it doesn't work because I've tried it and it's the correct syntax.

     

     

  • If you are trying to get what percentage is 426 out of 852 then

    Try this out..

    select (426 + .0)/ (852) * 100

    Result

    50.000

    Don't tell me it doesn't work because I've tried it and it's the correct syntax.

     

     

Viewing 6 posts - 16 through 20 (of 20 total)

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