Click here to Skip to main content
12,950,272 members (66,150 online)
Rate this:
 
Please Sign up or sign in to vote.
I am trying to change the data type of a column from nvarchar to numeric by using following query:-
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 7-Mar-13 23:21pm
Updated 8-Mar-13 9:02am
Maciej Los252.8K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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...
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

To change the data type of Column, it should be empty.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

did you checked the tables values?

the table have nvarchar values first u delete those values and try again...
  Permalink  
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)
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

Steps to do:
1) add new column
ALTER TABLE grimage ADD COLUMN tbbnum NUMERIC(10)


2) copy data to new column
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
ALTER TABLE grimage DROP COLUMN tbb


That's all!
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,829
CHill60 3,460
Maciej Los 2,953
Jochen Arndt 1,975
ppolymorphe 1,820


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100