Solved

Convert Dec to Int

Posted on 2009-07-09
3
178 Views
Last Modified: 2012-05-07
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
Comment
Question by:chrisryhal
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 24815277
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
 
LVL 17

Assisted Solution

by:pssandhu
pssandhu earned 250 total points
ID: 24815281
ALTER TABLE <TableName>
ALTER COLUMN <ColumnName> <New DataType>
Eg.
ALTER TABLE MyTable
ALTER COLUMN Amount INT
P.
0
 
LVL 2

Author Closing Comment

by:chrisryhal
ID: 31601691
Thanks!!  Got it converted
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
CONVERT date time to a different time zone. 2 52
Truncate vs Delete 63 105
How can i get data when i use where clause with group by? 3 35
Replace Dates in query 14 38
by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

775 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question