MySQL function?

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: Matt Alexander
Date:  
Subject: MySQL function?
Mike Starke said:
> On Mon, Sep 22, 2003 at 02:05:32PM -0700, Matt Alexander wrote:
> /_Mike Starke said:
> /_>
> /_> Is there a function in MySQL similar to that in Excel's "proper()"?
> /_>
> /_> For instance, I would like to do a select on a column that has
> /_> all CAPS and display the query in proper case (Mike versus MIKE).
> /_
> /_select concat(ucase(left(first_name,1)),lcase(SUBSTRING(first_name,2)))
> /_as First_Name from myTable;
>
> Thanks. Getting closer. My problem is when you have a value like "MR.
> FUDDS DELI"
> in the column; you get "Mr. fudds deli" instead of "Mr. Fudds Deli".


Hooboy... it doesn't get much worse that this, but here goes:

select
replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(replace(
replace(replace(replace(replace(replace(replace(replace(replace(concat(
ucase(left(first_name,1)),lcase(substring(first_name,2))),' a',' A'),' b',
' B'),' c', ' C'),' d', 'D'), ' e', ' E'),' f', ' F'),' g', ' G'),' h',
' H'),' i', ' I'),' j', 'J'),' k', ' K'), ' l', ' L'),' m', ' M'),' n',
' N'),' o', ' O'),' p', 'P'),' q', ' Q'),' r', ' R'), ' s', ' S'),' t',
' T'),' u', ' U'),' v', 'V'),' w', ' W'),' x', ' X'),' y', ' Y'), ' z',
' Z')
as Name from myTable;