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 2005 Forums
 Transact-SQL (2005)
 Change FieldType or Update to different fieldtype

Author  Topic 

gnaus
Starting Member

41 Posts

Posted - 2011-10-24 : 08:13:07
Dear reader,

Is it possible to change my field type (there are allready data in the column) or otherwise to update a column with data from an other column (from an other table) with an other fieldtype?

The fieldtype is varchar and I want to place the data in a column that’s fieldtype numeric


ALTER TABLE [dbo.Oefenomgeving$autRegForm_Verzekeringen] alter column VerzekerdBedrag Numeric(18,0);

Doesn’t work, see error:

Msg 8114, Level 16, State 5, Line 1
Error converting data type varchar to numeric.
The statement has been terminated.



And:

update [dbo.Oefenomgeving$autRegForm_Verzekeringen]
set Premie3=TeBetalenPremie


doesn’t work either, see error:

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




Is there a possibity to do this anyway?

Thank you very much!


GN

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2011-10-24 : 08:41:17
"Error converting data type varchar to numeric."
Solution depends on the data that is already in the table/column.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-10-24 : 08:59:50
select top 10 *
from Oefenomgeving$autRegForm_Verzekeringen
where VerzekerdBedrag like '%[^0-9]%'

might give you an indication as to which values are causing the problem.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-10-24 : 09:05:40
unless you filter out non numeric values from you column you wont be able to do the alter column or update. check using last provided suggestion presence of non numeric data and then decide how you want to change before you try to convert them to numeric types.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

gnaus
Starting Member

41 Posts

Posted - 2011-10-26 : 03:33:39
thank you for the reactions!!
It's clear!

greetings,

GN
Go to Top of Page
   

- Advertisement -