...

View Full Version : Title case



BubikolRamios
04-28-2009, 08:51 PM
For future search/use

if jou have:

SLOVENIA
ENGLAND

and woulld like to have

Slovenia
England

This is the way:



update table
set field = Concat(Upper(Substr(field ,1,1)),Lower(Substr(field ,2,length(field ))))

Old Pedant
04-28-2009, 09:47 PM
Ummm...but what happens if you have:

NORTH AMERICA
NEW SOUTH WALES

????

Your code would produce

North america
New south wales

I *think* you can do this much better in MySQL using a regular expression, though I've never tried it. Generally, you will be better off doing "title case" (a.k.a. "proper case") in your server side language (e.g., PHP, ASP, JSP, etc.) than trying to do it in the SQL. Or you could even do it in JavaScript in the browser easier than in SQL.

Fumigator
04-28-2009, 10:39 PM
Yeah just use PHP's function ucwords().

http://us.php.net/manual/en/function.ucwords.php



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum