Friday, February 24, 2012

Convert Money to Varchar(50)

I created a table using sql, and I accidentally made one of the fields a money datatype and I meant to make it a Varchar(50). Is there an easy way to change the datatype with an sql update/convert statement. I want to make the change permanent. As I need it to reflect on a couple of different databases with this same table name. Here is the update statement I have been trying.

update ibapoorderline set salestype=convert(varchar(50),salestype)

There is currently no data stored in the column salestype. They are all null. I just want to change the datatype so I can begin adding data.

Thanks in advance.Drop the column and re-add it.

create table f00 (f00id int, f00monex money)
go
--whoops!
alter table f00 drop f00monex
go
alter table f00 add f00varchar varchar(50) NULL
go

Convert will only convert the data for output, it won't change the datatype of the column.|||Thank you so much. What I was looking for was the drop line. That helps a lot. I couldn't remember how to get rid of a column and then add it back in with a different datatype.|||No problem. Note that when you drop/add it moves the column to the bottom of the column list. Not sure if you care about that...

Look up ALTER TABLE in Books Online for more syntax.

No comments:

Post a Comment