Percentage value not appearing

  • I can't get the results to work correctly...

    I get the 55 instead of 55.41

    The SUM of Student is 665 and divide that by 12 it should be 55.41 (as done on a calculator)

    How do I get this results then ?

  • It will be to do with data types. You need one of the operands to be non-integer to get this to work. Try this:

    SELECT 665/12

    SELECT CAST(665 AS MONEY)/12

    ..and you'll see what I mean.

  • Thanks, how do I CAST a column called [Student] so it will work?

  • Richard Warr (11/3/2010)


    It will be to do with data types. You need one of the operands to be non-integer to get this to work. Try this:

    SELECT 665/12

    SELECT CAST(665 AS MONEY)/12

    ..and you'll see what I mean.

    MONEY is basically DECIMAL (19,4). SO i would suggest using DECIMAL (s,p) are per your requirement.. To learn more about DECIMAL, please refer Books Online or MSDN..

  • akhlaq768 (11/3/2010)


    Thanks, how do I CAST a column called [Student] so it will work?

    Replace the "665" with the column name.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 5 posts - 1 through 4 (of 4 total)

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