Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help changing float datatype to varchar datatype

Status
Not open for further replies.

bjensen44

Programmer
Aug 7, 2003
11
US
I need to change one SQLServer7 table's field datatype from float to varchar (or another datatype that will accept alphanumeric data).

Sounded simple, but I've spent the whole day fixing the DB after the conversion changed the last significant digits of integer data to zeros. I set the field length to 10 when the longest integer of the float datatype was 7 digits and no decimals were involved. However, the float precision was set at 53, so I wonder if there's some intermediate step I need to take.

Now that I've got the DB repaired, I need to take another whack at converting the field's datatype WITHOUT corrupting the DB. Anybody have any hints or cautions?

Thanks!

 
Create an intermediary field.

UPDATE MyTable
SET MyNewField = CAST(myFloat as varchar(x))

???
 
Thanks, zooraw.

I've already accomplished what I needed to do by changing the field's datatype to varchar with a length of 50. (Turns out that float has a hidden length of 30.) After the field type was changed, I ran a repair routine I'd written earlier today to read the contents of the field into a variable then update the field with the same (but recast) data. Before the repair routine, the data in the changed field was screwed up, but now it's fine.

I'm still left wondering if there's not an elegant way to do such a simple task.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top