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
.
Change data types in Design view If you do not have the table open, in the Navigation Pane, right-click the table that you want to change, and then click Design View on the shortcut menu. Locate the field that you want to change, and select a new data type from the list in the Data Type column. Save your changes.
For example, a type of INT which stands for integer in SQL server can only accept whole numbers, decimal values are not allowed.
Data types can be converted either implicitly or explicitly. Implicit conversions are not visible to the user. SQL Server automatically converts the data from one data type to another. For example, when a smallint is compared to an int, the smallint is implicitly converted to int before the comparison proceeds.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With