Error handling

  • Comments posted to this topic are about the item Error handling

  • Thanks for this easy question.

  • 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.

  • This was removed by the editor as SPAM

  • 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.

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

    Error Code 220 is an arithmetic overflow error.

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

  • 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.

  • 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
  • select * from sys.messages where message_id = 220;

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

    Good one.

    Thanks.

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

  • 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

  • It returns indeed 220, but that is an errornumber.

    So I doubted whether 220 or error.

    I have chosen 220.

  • Hi Tom,

    Thanks for post, I agree with you.

  • 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 15 total)

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