How can I make the following always return in proper case?  First Character to upper case.

Posted on 2008-11-06
Last Modified: 2010-03-19
How do I change a first and last name that are in uppercase to Proper or Title case where the first character of the first and last name are capitol and the rest lower case. This is done in a Stored Procedure. Thanks.
Question by:expertsexchangehunter
    LVL 13

    Expert Comment

    LVL 13

    Expert Comment

    LVL 37

    Accepted Solution

    select lower(your_column)
    from your_table

    will return the name in all lower case
    select upper(left(your_column,1)) + lower(substring(your_column,2, charindex(',', your_column) -1)) +
         upper(left(your_column, charindex(',', your_column)+1)) + lower(substring(your_column,charindex(',', your_COLUmn)+1, len(your_column)))

    Author Comment

    Here is my code
    select upper(left(FirstName,1)) + lower(substring(FirstName,2, charindex(',', FirstName) -1)) +
         upper(left(LastName, charindex(',', LastName)+1)) + lower(substring(LastName,charindex(',', LastName)+1, len(LastName)))

    here is what happened when I ran it with a valid First and Last name
    Invalid length parameter passed to the substring function.
    What is wrong with my code?

    Author Comment

    I used
    select upper(left(FirstName,1)) + lower(substring(FirstName,2, len(FirstName)-1)) + ' ' +
    upper(left(LastName,1)) + lower(substring(LastName,2, len(LastName)-1))
    to get the desired results

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
    This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now