Solved

SQL Server Help with Update Statement

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

13 Experts available now in Live!

Get 1:1 Help Now