Modify field contents.  Remove "Atten" from a field that contains "Atten: First Name Last Name"

Posted on 2008-11-03
Last Modified: 2012-05-05
Please help me with a SQL statement that will remove "Atten" from the Attent field that contains rows with:
Jane Doe
Atten Jane Doe
Attention Jan Doe
Jon Doe
Select * from Leas where Attent like 'Atten%'
will return the appropriate rows.  What addtional syntax will remove only the Atten and Attention and leave the names in the Attent field?
Question by:LFreehauf
  • 2
LVL 17

Expert Comment

Comment Utility
select case
when left(attent,9)='Attention' then right(attent,len(attent)-9)
when left(attent,5)='Atten' then right(attent,len(attent)-5)
else attent
AS TrimmedAttentValue
from Leas

Author Comment

Comment Utility
I think I need to clarify.
I want to delete any occurrence of "Atten" and "Attention" from the "Attent" field.
Your select statement returns data without the Atten or Attention (Thank You).  However, I want to modify data; remove ("Atten" and "Attention") from the field:
Example of 4 rows and the Attent field prior to modifications:
Jan Doe
Atten Jan Doe
Attention Jon Doe
Jon Doe

Example of the same 4 rows and the Attent field after the modification (desired results):
Jan Doe
Jan Doe
Jon Doe
Jon Doe
LVL 17

Accepted Solution

aflockhart earned 500 total points
Comment Utility
To modify the original data, use the UPDATE syntax below:  (I have also amended the code to delete the space between "Attention" or "Atten", and "Jane Doe")
Note that this will fail to find occurences where the word "attention" is spelled wrongly; and if there is any punctuation like "Attten : Jane Doe" it may give unwanted results

update leas 

set attent=

select case

when left(attent,9)='Attention' then ltrim(right(attent,len(attent)-9))

when left(attent,5)='Atten' then ltrim(right(attent,len(attent)-5))

else attent 


where left(attent,5)='Atten' 

Open in new window


Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

728 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

11 Experts available now in Live!

Get 1:1 Help Now