Casting Tiny Numbers

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 720983

    Comments posted to this topic are about the item Casting Tiny Numbers

  • Jeff Moden

    SSC Guru

    Points: 997169

    Good basic question, Steve.  My only objection would be the title of the question itself because this also occurs for much larger numbers and larger VARCHARs.

     

    --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".
    "Dear Lord... I'm a DBA so please give me patience because, if you give me strength, I'm going to need bail money too!"

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

  • Mr. Brian Gale

    SSC-Insane

    Points: 23169

    While I agree with Jeff, it doesn't apply to all larger numbers.  TINYTINT, SMALLINT, and INT's have the same behavior but bigints throw an error instead.

    As for the VARCHAR value, as long as it is 1 or more under the number of digits in the variable you will get the answer (or a derivative of it) from the QOTD.

  • Steve Jones - SSC Editor

    SSC Guru

    Points: 720983

    This question isn't designed to cover all possibilities. Writing questions like that is hard and fraught with perils. You are welcome to submit your own questions about other types of numerical values.

     

  • Mr. Brian Gale

    SSC-Insane

    Points: 23169

    I wasn't trying to rag on you Steve.  I was just commenting on the different data types (at least in SQL 2008 R2 which I tested it in) that give that result.

    Testing it against all SQL versions and all datatypes would be a nightmare.  And what happens when a SP or CU changes the behavior?  I like the question and the link is good too.  Tells you what to expect with most data types!

  • Jeff Moden

    SSC Guru

    Points: 997169

    Steve Jones - SSC Editor wrote:

    This question isn't designed to cover all possibilities. Writing questions like that is hard and fraught with perils. You are welcome to submit your own questions about other types of numerical values.

    Oh no... I get that.  It was a good question.

    --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".
    "Dear Lord... I'm a DBA so please give me patience because, if you give me strength, I'm going to need bail money too!"

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

  • Stewart "Arturius" Campbell

    SSC Guru

    Points: 71915

    This has bitten me in the past (front-end developers not making provision for very large integers).

    ____________________________________________
    Space, the final frontier? not any more...
    All limits henceforth are self-imposed.
    “libera tute vulgaris ex”

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

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