Friday, March 20, 2009

First letter uppercase in MySQL

So you have all types of string in a mysql database.

Eg:

MySQL
MYSQL
mysql
MySqL

And you want to make the first letter of each record uppercase and the rest lowercase.
Here is the update syntax for this job:

UPDATE mytable SET myfield=CONCAT(UPPER(SUBSTRING(myfield, 1, 1)), LOWER(SUBSTRING(myfield FROM 2)))

1 comment:

Anonymous said...

nice code dude...