x

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

avatar image

Lonnie Thomas
11 1 1 3

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)

go

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

avatar image

TimothyAWiseman
15.6k 22 51 38

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

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

SQL Server Central

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

Topics:

x36

asked: Oct 20, 2009 at 11:52 AM

Seen: 3826 times

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

Copyright 2016 Redgate Software. Privacy Policy