SQL UpperCase Third Character in Column - SQL Server 2005

I am trying to upper case the 3rd character in a column
where the first two characters are 'Mc%'

Something like:

update customer
set last_name =
UCase(Left(last_name,3))
where last_name like 'Mc%'


Can someone please verify my code?

Thanks!
robthomas09Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

chapmandewCommented:
something like this:

update customer
set last_name = left(last_name, 3) + upper(substring(last_name, 3, 1)) + substring(last_name, 4, len(last_name))
where last_name like 'Mc%'
0
LowfatspreadCommented:

update customer
set last_name = 'Mc' + upper(substring(last_name, 3, 1)) + substring(last_name, 4, len(last_name))
where last_name like 'Mc[a-z]%'
0
mavalphaCommented:
Left(last_name,3) would return the first three characters together, not just the 3rd character by itself.  Plus, you're truncating the rest of your last name, so "Mcdonald" would become "MCD" and nothing else.  You need several substrings to accomplish this.  ("Mc", third letter, and everything else).  You could try the string "Replace" function, but this runs the risk of accidental replacements if you don't anticipate duplicate letters in the person's name.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

chapmandewCommented:
whoops..you're right:

update customer
set last_name = left(last_name, 2) + upper(substring(last_name, 3, 1)) + substring(last_name, 4, len(last_name))
where last_name like 'Mc%'
0
halfbloodprinceCommented:
THIS WORKS:

update customer
set last_name = Left(last_name,2) + Upper(SubString(last_name,3,1)) + SubString(last_name,4,len(last_name))
where last_name like 'Mc%'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Aneesh RetnakaranDatabase AdministratorCommented:

update customer
set last_name = STUFF(last_name, 3,1, UPPER(SUBSTRING(last_name,3,1) ) )
where last_name like 'Mc%'
0
robthomas09Author Commented:
Thanks everyone - I'll try it out now!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.