Error handling

  • Junior Galvão - MVP

    SSCertifiable

    Points: 6376

    Comments posted to this topic are about the item Error handling

  • patricklambin

    SSCrazy Eights

    Points: 9964

    Thanks for this easy question.

  • Richard Warr

    SSCertifiable

    Points: 6955

    Only an easy question if you know all of the SQL Server error codes. Otherwise the only way to get it right is to cheat and run the code.

    _____________________________________________________________________
    MCSA SQL Server 2012

  • This was removed by the editor as SPAM

  • Ed Wagner

    SSC Guru

    Points: 286957

    I suppose you could run the following for each of the messages listed:

    select * from sys.messages where message_id = n;

    Either way, it was a nice, clear question. Thanks.

  • Scott Arendt

    SSCertifiable

    Points: 7611

    I think that the explanation should be expanded to include what exactly error code 220 means.

    Error Code 220 is an arithmetic overflow error.

  • akljfhnlaflkj

    SSC Guru

    Points: 76202

    I knew it would error with some kind of overflow error but I don't have all the error codes memorized.

  • doug.davidson

    SSCommitted

    Points: 1522

    Iwas Bornready (6/11/2015)


    I knew it would error with some kind of overflow error but I don't have all the error codes memorized.

    +1

    Figured it out by elimination:

    1000 - wrong

    220 - no clue

    255 - max tinyint value

    Error - different type then @@ERROR

    Therefore, 220, which I had no clue about must the correct error code for this question.

  • Luis Cazares

    SSC Guru

    Points: 183531

    doug.davidson (6/11/2015)


    Iwas Bornready (6/11/2015)


    I knew it would error with some kind of overflow error but I don't have all the error codes memorized.

    +1

    Figured it out by elimination:

    1000 - wrong

    220 - no clue

    255 - max tinyint value

    Error - different type then @@ERROR

    Therefore, 220, which I had no clue about must the correct error code for this question.

    Unfortunately, I couldn't be sure that 1000 and 255 were coincidences with the error code.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • SQL_Hunt

    SSC-Dedicated

    Points: 33261

    select * from sys.messages where message_id = 220;

    It says, "Arithmetic overflow error for data type %ls, value = %ld."

    Good one.

    Thanks.

  • Revenant

    SSC-Forever

    Points: 42467

    I also had to consult the table. Thanks, Junior!

  • TomThomson

    SSC Guru

    Points: 104762

    error is obviously wrong, and if 1000 were the message number for tinyint overflow this would be a disgraceful trick queston and I don't mind getting those wrong, 255 (the limit of tinyint) would be a strange coincidence so it seemed worth going for 220.

    It's interesting to see that SQL Server, even in it's 64 bit form, still thinks in terms of 32 bit integers so that the message when feeding in 2147483648 for a tinyint or smallint is quite different from that got by feeding in 2147483647 or lower - message number 8115 instead of 220.

    Tom

  • Arno Kwetters

    Hall of Fame

    Points: 3335

    It returns indeed 220, but that is an errornumber.

    So I doubted whether 220 or error.

    I have chosen 220.

  • Junior Galvão - MVP

    SSCertifiable

    Points: 6376

    Hi Tom,

    Thanks for post, I agree with you.

  • Koen Verbeeck

    SSC Guru

    Points: 258905

    Nice question, thanks.

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

Viewing 15 posts - 1 through 15 (of 16 total)

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