Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

SQL Server Help with Update Statement

Posted on 2014-02-20
2
Medium Priority
?
252 Views
Last Modified: 2014-02-20
Hi.. I need to clean up data in a LASTNAME field.
I need to find and replace all the 'ii' and replace with 'II' and find all the 'iii' and replace with 'III'



The data looks like this

jones  ii
smith iii
brown
green ii


Need it look like this
Jones II
Smith III
Brown
Green II


Basically capitalize the '2nd' and '3rd'
0
Comment
Question by:JElster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Steve Wales earned 1600 total points
ID: 39874459
Check the Replace Function: http://technet.microsoft.com/en-us/library/ms186862.aspx

The space before the string to replace should make sure it picks it up at the end of the string, incase there's a last name that has ii or iii as a part of the actual name and not the suffix.

update table1
set lastname = replace(lastname, ' iii', ' III');

update table1
set lastname = replace(lastname, ' ii', ' II');

Open in new window


You can check what the output of the update would look like before the update by doing:

select lastname, replace(lastname, ' ii', ' II') from table1;

Open in new window

0
 
LVL 11

Assisted Solution

by:John_Vidmar
John_Vidmar earned 400 total points
ID: 39874651
UPDATE	yourtable
SET	lastname = replace(replace(lastname, ' iii', ' III'), ' ii', ' II')
WHERE	lastname like '%ii%'

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

649 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