Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Title case

  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,963
    Thanks
    120
    Thanked 76 Times in 76 Posts

    Title case

    For future search/use

    if jou have:

    SLOVENIA
    ENGLAND

    and woulld like to have

    Slovenia
    England

    This is the way:

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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,007
    Thanks
    79
    Thanked 4,434 Times in 4,399 Posts
    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.

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Yeah just use PHP's function ucwords().

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •