simple division

  • I do this:

    select 18/94

    and got 0!

    answer is supposed to be .19. I tried

    select convert(decimal(5,2), 18.94)

    and still got 0.00.

    I don't understand!

    How to do simple division?

  • KoldCoffee (8/7/2014)


    I do this:

    select 18/94

    and got 0!

    answer is supposed to be .19. I tried

    select convert(decimal(5,2), 18.94)

    and still got 0.00.

    I don't understand!

    How to do simple division?

    You got zero (0) because you are doing integer division. Try this: select 18/19. -- << be sure to include the decimal point at the end.

  • select 18/19 still gives me zero.

    Someone, please show me how to divide integers so that 94/18 gives me .19

    I know I've done this before and can't understand where this is coming from.

    I just want to be able to divide.

  • select 18 * 1.0/94

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • too late, I figured it out. Each number has to be divided seperately.

    select cast(18 as float)/cast(19 as float);

    select convert(decimal(5,2),18)/convert(decimal(5,2), 19);

    Spare me the long winding road to nowhere

  • Thanks Scott, for the answer!!!!!!

  • thanks lynn, for being forthcoming (finally!)

  • KoldCoffee (8/7/2014)


    too late, I figured it out. Each number has to be divided seperately.

    select cast(18 as float)/cast(19 as float);

    select convert(decimal(5,2),18)/convert(decimal(5,2), 19);

    Spare me the long winding road to nowhere

    FWIW - you only need to cast/convert one of those values in order for it to work properly.

    You can also shorthand it like Scott and Lynn showed as well.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

Viewing 8 posts - 1 through 7 (of 7 total)

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