How can i convert a price field which is currently varchar to a decimal so my prices will order correctly?

I am using MYSQL.

I have a varchar field which i incorrectly used for a price. Now the ordering of this table will not work correctly putting anything over 1000 to the bottom of the list.

I need to convert this price field in an existing POPULATED database from varchar to decimal i guess?

Any help would be appreciated.

Answers


Simply use the ALTER TABLE statement.

If for example the table is called 'products' and the field is called 'product_price' you could simply use:

ALTER TABLE products MODIFY COLUMN product_price DOUBLE;

NB: As with anything, I'd be very tempted to make a backup of the data (via mysqldump) prior to performing this operation - it'll take seconds and it's always better to be safe rather than sorry. :-)


Need Your Help

Use of Literal vs GenericHtmlControl and viewstate reduction

asp.net controls viewstate

I've been working on ASP.NET for just over a year now, and I've come upon an interesting thought that I'd like feedback on.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.