Results 1 to 11 of 11

Thread: quick question

  1. #1
    Join Date
    Sep 2003
    Posts
    4

    Unanswered: quick question

    Write a sql that divides 8 by 3 cast 3 as a decimal rounded to 2 places \


    ?????????????????????????????


    HOW do i do this im confused and new to this!!!

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    At least one of your values must be non-integer, and you must cast your final results to two decimal places of accuracy. Otherwise, SQL Server works with integers by default becuase they can be processed more quickly, and it will thus round off your answer.

    All these work:
    select cast(8/cast(3 as decimal(10,2)) as decimal(10,2))
    select cast(cast(8 as decimal(10,2))/cast(3 as decimal(10,2)) as decimal(10,2))
    select cast(8/3.0 as decimal(10,2))

    ...but this does not:
    select cast(8/3 as decimal(10,2))

    blindman

  3. #3
    Join Date
    Sep 2003
    Posts
    4
    Thanks a lot!!!

  4. #4
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    bm: SQL does not choose integers because they are easy to work with...That's funny even to think that way

    Read BOL on datatype conversion rules!!!

  5. #5
    Join Date
    Dec 2002
    Posts
    63
    rdj, you need to give it a rest already.

  6. #6
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    Pigeon: I would, but bm never gives up Plus, his last answer was really funny, so I couldn't resist

  7. #7
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    You're welcom, dirtysouthchick!

    Glad I could be of help to you.

    blindman

  8. #8
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    go to bed, bm, tomorrow is just another day

  9. #9
    Join Date
    Oct 2001
    Location
    Naples, FL
    Posts
    273
    Just curious rdjabarov, why the beef with Blindie?
    ---------------
    Ray Higdon MCSE, MCDBA, CCNA

  10. #10
    Join Date
    Oct 2001
    Location
    Naples, FL
    Posts
    273
    Nevermind, I just caught up reading the other posts
    ---------------
    Ray Higdon MCSE, MCDBA, CCNA

  11. #11
    Join Date
    Jul 2003
    Location
    San Antonio, TX
    Posts
    3,662
    I don't have a beef, I just see that sometimes all of us (or some of us) prefer a p***ing contest over the opportunity to hear each other out. And I am as guilty in doing this as the next guy. I just don't want to be a part of a place like this, so I hope that we all re-think the reason why we chose to be here in the first place.

    Other than that, - life is good

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •