Solved

SQL Server Help with Update Statement

Posted on 2014-02-20
2
243 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 22

Accepted Solution

by:
Steve Wales earned 400 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 100 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

688 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