Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case formatting on "Mc" names

Status
Not open for further replies.

leftfldr

Programmer
Mar 30, 2005
23
US
Using SQL 2005 I have a contact name field where the first and last names are stored together. Some of the last names start with Mc. I need a script that will capitalize the letter after the Mc. Here are examples of data in the table.
Bill Mcconnell
Jim Mccall
Joe Smith
Tim Lansing
Dan Mcqueen

Any help would be appreciated.
 
NOT TESTED AT ALL!!!!!!!!!!!!!!!
Code:
SELECT CASE WHEN CHARINDEX(' Mc', NameField) = 0
                 THEN NameField
            ELSE LEFT(NameField, CHARINDEX(' Mc', NameField)+2)+UPPER(SUBSTRING(NameField,CHARINDEX(' Mc', NameField)+3,1))+SUBSTRING(NameField,CHARINDEX(' Mc', NameField)+4,8000) END AS Name
FROM YourTable



Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
BTW that should work ONLY if you have only First name and Last Name stored together, not if you have something like this:

Bill Mc Mcconnell
Bill Mcconnell Mcconnell
etc.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top