What is an Arithmetic Overflow?

  • I'm converting varchar data to datetime and I get an arithmetic overflow error after about 25 thousand records. I've got a work around but what the heck is an arithmetic overflow? 

     

    Thanks

    Mardy

     

     

  • Mardy,

    The smalldatetime and datetime datatypes are basically decimal datatype with a reference from a beginning period of time.  Each whole number equals 1 day.  That's why you can do "select getdate() + 1.5" and it will give you the exact date and time 1 1/2 days from the time you ran it.

    smalldatetime limits are:  January 1, 1900, through June 6, 2079

    datetime limits are:  January 1, 1753 through December 31, 9999

    Most likely you have a date that is out of the limits of the datatype you are using or when the varchar is converted it might have a character in there that cast or convert doesn't recognize for the format of a date.

     


    Brad

  • Even simpler considering datetime values are stored as two part intergers.

    Datetime is two 4 byte integers (equal to two int datatypes together) and smalledatetime is two 2 byte intergers (equalk to two smallint datatypes together).

    So you have a potenially valid range of supportable numbers you can enter.

    So now image you are using a tinyint instead. This means you are using 1 byte or a valid integer between 0 and 255. If you try to enter anything greater or less than that range you get an "Arithmetic Overflow" because the value cannot be supported by the choosen datatype.

    Basically "Arithmetic Overflow" boils down to trying to input a number outside the allowed range.

     

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

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