Georg Weber
Georg Weber

Reputation: 45

Convert varchar to integer

I have a database with a price field. This price field was defined as varchar. The Values is someting like 123,45. I need to convert this varchar field to integer in all records. How i can resolve this?

Upvotes: 0

Views: 490

Answers (3)

Wistar
Wistar

Reputation: 3790

This worked better for me. It's from the documentation.

ALTER TABLE yrtable CHANGE columnname columnnameagain BIGINT NOT NULL;

Upvotes: 0

iowatiger08
iowatiger08

Reputation: 1962

You could use the cast method or alter the table

ALTER TABLE yrtable ALTER COLUMN `price` DECIMAL (10,2);

Upvotes: 0

Hal
Hal

Reputation: 1264

If it is all within mySQL that you are doing your conversions, CAST is your friend.

http://dev.mysql.com/doc/refman/5.0/en/cast-functions.html#function_cast

If you are doing it outside of mysql, virtually all languages have cast functions that should be able to take an input as a string and attempt to convert it to a desired value - for example, c# might use int.Parse(string);

Upvotes: 2

Related Questions