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

Paralells Confixx Redirect with no htaccess file to Wordpress

html wordpress .htaccess indexing parallels

I use shared hosting and have previously had a dreamweaver site on my domain. It is all managed on Confixx. I've installed wordpress via software on the Confixx and it set itself up inside of the h...