I have assigned the data type of one of the columns of a table I have created as int
. My problem is that it is not showing decimal places when I run a query against it.
How do I correct the data type of this column so that it accepts decimal places?
Table is dbo.Budget
and the column concerned is called ROE
.
Easy - just run this SQL statement
ALTER TABLE dbo.Budget
ALTER COLUMN ROE DECIMAL(20,2) -- or whatever precision and scale you need.....
See the freely available MSDN documentation on what exactly the precision, scale and length in decimal numbers are and what ranges of values are possible
Just to have this stated clearly:
If there is no data in the table, or not that much, then the simple ALTER TABLE
statement (as described in the other answers here) is fine.
But, if there is a lot of data (millions of rows, or possibly less depending on the size of the table) and/or a lot of contention on the table and not much opportunity for a full downtime / maintenance window, then it requires a different approach, such as what I described in this answer: Narrowing the Data Types on a very large table .
You can execute this simple sql statement
Alter table yourtable
Alter Column yourtable_column Decimal(10,2)
you can set decimal precision and scale whatever you need.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.