• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 189
  • Last Modified:

Convert Dec to Int

I have a DB column that by mistake I made a decimal(18, 2) datatype.  What I have now is the fact I have 3000 records in my table now and need it to be an int datatype.   Is there an easy way to fix this?  Even though its a decimal datatype there are no records that are in decimal formal.
0
chrisryhal
Asked:
chrisryhal
2 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
create a new column with int / bigint datatype
ALTER TABLE tableName ADD newColumn int
UPDATE tableName SET NewCOlumn = CAST (decimalColumn as int )
ALTER TABLE TableName DROP COLUMN decimalColumn
exec sp_Rename 'tableName.NewColumn', 'DecimalColumn', 'Column'
0
 
pssandhuCommented:
ALTER TABLE <TableName>
ALTER COLUMN <ColumnName> <New DataType>
Eg.
ALTER TABLE MyTable
ALTER COLUMN Amount INT
P.
0
 
chrisryhalAuthor Commented:
Thanks!!  Got it converted
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now