mysql: convert number to string

by prettyscripts on 2009-05-29 10:51:17

miscsql

to copy value from a column in table a to a column in table b, the syntax is straight forward:

Code:

insert into new_table (new_column)
select old_column from old_table

but when new_column is varchar and old_column is integer, you will get an error.

you need to use cast function. update the above query as follows:

Code:

insert into new_table (new_column)
select cast(old_column as char) from old_table

Tags: convert, mysql, number, string

No feedback yet

Leave a comment


Your email address will not be revealed on this site.
PoorExcellent
note: all comments are moderated. do not spam and do not advertise. only comments relevant to the post will be published.
(Line breaks become <br />)
(For my next comment on this site)
(Allow users to contact me through a message form -- Your email will not be revealed!)