Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Trouble converting varchar to float

Author  Topic 

KidSQL
Yak Posting Veteran

88 Posts

Posted - 2005-04-07 : 09:06:04
Hello,

I am having trouble converting a varchar column of length 255 into a float datatype. I am using alter table to add a new column of type float and I'm then selecting the contents of the old varchar column into it, using convert in the process like so:

alter table mytable
add newcolumn float null

update mytable
set newcolumn = convert(float, oldcolumn)

But I get the following error message:

Server: Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to float.

Does anyone have any ideas what I may be doing wrong here? Many thanks in advance for any help.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-04-07 : 09:32:21
Make sure that oldcolumn does not have any non numeric charaters

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2005-04-07 : 09:33:02
You've got data in your oldColumn that can't convert. see which they are with:

Select oldColumn from myTable where isNumeric(oldColumn) = 0

Be One with the Optimizer
TG
Go to Top of Page

KidSQL
Yak Posting Veteran

88 Posts

Posted - 2005-04-07 : 09:33:22
Just checked, that was it. Can't believe that eluded me. Thanks!
Go to Top of Page
   

- Advertisement -