Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 String Replacement

Author  Topic 

ddamico
Yak Posting Veteran

76 Posts

Posted - 2009-06-26 : 14:35:59
Good day. I am working on doing a replace of various words within a character field. Essentially, I have a table that contains several titles such as (Mr., Mrs., Dr., Drs., etc)

I need to write a Select statement the will remove all of these possible titles witin a character field. I am hoping to accomplish this with a single select statement without having to do replace(replace(....))

I wanted to try to avoid using a cursor. Any assistance would be appreciated.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-06-26 : 14:51:36
assuming you wont have any other . characters other than in title you can use below

SELECT SUBSTRING(Name,CHARINDEX('.',Name)+1,LEN(Name)) FROM YourTable
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2009-06-26 : 15:46:48
The nested replace may be the most efficient and reliable method.
Visakh's solution won't work (as he correctly implied) if you have names with Middle initials like 'Craig T. Nelson'. Other names may be 'Mr. and Mrs. Smith' which could easily be handled by nested replace but difficult with generic replacement algorithms.

Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -