Change an int field to a numeric(3,2)

What is the best way to change an int field to a numeric(3,2)?

more ▼

asked Oct 20, 2009 at 11:52 AM in Default

Lonnie Thomas gravatar image

Lonnie Thomas
11 1 1 1

Are you sure your all of your ont values Will fot into decimal(3,2)? You Will get overflow If the int are higher than 9. Decimal(3,2) handles values from 0.00 to 9.99
Oct 20, 2009 at 02:08 PM Håkan Winther
Don't forget negative -0.01 to -9.99
Oct 20, 2009 at 05:27 PM Peso
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

If all of your integers are small enough to fit into that size of numeric column, then just use alter column, here is an example:

create table intTable (col1 int)

insert into intTable
values (1)

insert into intTable 
values (2)


alter table intTable
    alter column col1 numeric(3, 2)

However, if you try it with values that are too large, it will give you an arithmetic overflow error. In that case, you either need to increase the size of the numeric type you are converting it to or remove the large values first.

more ▼

answered Oct 20, 2009 at 12:14 PM

TimothyAWiseman gravatar image

15.6k 21 23 32

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Oct 20, 2009 at 11:52 AM

Seen: 2496 times

Last Updated: Oct 21, 2009 at 10:18 AM