Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to change the data type of a column from nvarchar to numeric by using following query:-
SQL
alter table grimage alter column tbb numeric(10)


but i got the following error :-
Error converting data type nvarchar to numeric.<br />
The statement has been terminated.
Posted
Updated 8-Mar-13 9:02am
v2

Hi,

Check the values in that column because String might be stored so it cant convert the values...If it so then update the values and change.
 
Share this answer
 
Hey have u checked the table values if not please check your table values first.Youtr table has some text values defiantly so first remove them after that you can alter your table...
 
Share this answer
 
v2
To change the data type of Column, it should be empty.
 
Share this answer
 
did you checked the tables values?

the table have nvarchar values first u delete those values and try again...
 
Share this answer
 
Comments
Davidduraisamy 8-Mar-13 6:57am    
No need to delete the values..He can update the string values to numeric...Thats enough..
itsmehaboob 8-Mar-13 7:28am    
how can you convert string value to numeric?
e.g. (a to numeric)
Steps to do:
1) add new column
SQL
ALTER TABLE grimage ADD COLUMN tbbnum NUMERIC(10)


2) copy data to new column
SQL
UPDATE grimage SET grimage.tbbnum = t1.tbbnum
FROM grimage INNER JOIN
    (
    SELECT CONVERT(NUMERIC(10), t1.tbb) AS tbbnum FROM grimage
    ) AS t1 ON grimage.id = t1.id


3) remove unused column
SQL
ALTER TABLE grimage DROP COLUMN tbb


That's all!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900