As long as each value in the varchar can be cast to a decimal, you’re fine.



I would do these steps:



1)      Add a column to table: temp_col numeric(10,4)

2)      Execute: UPDATE table SET temp_col = CAST(varchar_col AS numeric(10,4))

3)      Verify data

4)      Alter table to remove varchar_col

5)      Alter table to rename temp_col to varchar_col



Also note that this change will likely create some issues with your TAFs. 
Mostly around quoting. In the places where you write to this column (insert and 
update actions) you’ll want to turn off quoting (set Quote Value to False). You 
may also have to re-drag the columns into the various db actions to update the 
column type in the TAFs. I can’t be sure if this will be necessary, but it will 
be obvious in that you’ll get an error as soon as you make the change.



Robert







From: WebDude [mailto:[email protected]]
Sent: Tuesday, July 31, 2012 7:52 AM
To: [email protected]
Subject: TeraScript-Talk: O.T. - MSSQL 2008 Changing VarChar to Decimal



Hey Folks,



Sorry for the off topic question.



I have 2 columns in the DB that need to be converted from a VarChar to Decimal. 
I have noticed in the past that using Alter Table will throw an error if data 
is going to be truncated or cannot be changed. There are probably 250,000 
records and of course I am leery about doing this so I don't mux the data. I am 
planning to copy some of the data to another table to experiment on before 
doing the big change. I assume NULL will stay NULL as other changes have been 
like this. I have changed numeric data before with no problems but this the 
first time converting from a VarChar. There are around 5000 records that I will 
need to "fix" in order to do this before moving forward. Does anyone see any 
problems with doing this this way?



Thanks for any feedback...



  _____

To unsubscribe from this list, please send an email to [email protected] 
with "unsubscribe terascript-talk" in the body.




----------------------------------------

To unsubscribe from this list, please send an email to [email protected] 
with "unsubscribe terascript-talk" in the body.

Reply via email to