Sum & Count error

  • I've been trying to run this query but the results from the divide query are not right. Where am I going wrong

  • Attempt #1 seems right to me. What is "not right" about it and how do you know that it is wrong?

    [font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
    Proactive Performance Solutions, Inc.
    [/font]
    [font="Verdana"] "Performance is our middle name."[/font]

  • It looks like you are dividing 2 integers and getting an integer as the result. Try casting one of the values to something like DECIMAL (10,2).

    To demonstrate the issue have a look at the result of the following 2 statements

    select 1/2

    select 1.0/2

    The first returns 0 and the second 0.5. I think this is the sort of thing that you are experiencing.

  • I know its wrong because when I look at my output and try and work it out manually its wrong. Thats why I'm wondering if my query is giving me the right output.

    My data types are the same ?

    select 80./0. should give me the

    Msg 8134, Level 16, State 1, Line 1

    Divide by zero error encountered.

    but its giving me 202 ? I'm puzzled

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

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