Tuesday, February 24, 2009

Convert mysql output to another data type

Sometimes there's a need to convert a datatype from one to another in the database, for example, if the data is store in utf8 format in the database and you want it output to latin1 datatype, one way to do this is using the convert function that mysql provide. Here a snippy code for that:

"SELECT CONVERT(fieldname USING latin1) as newfield FROM dbtable"

More detail can be found on: MYSQL CONVERT FUNCTION