Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how do I modify a string field?

Status
Not open for further replies.

karen4201

Programmer
Mar 9, 2006
37
US
Let's say I have a table field that contains "Joe, Bob, Mike"
and the names might be rearranged (like "Bob, Joe, Mike"). Is there an easy way to update ALL fields that contain "Bob" so that the field would simply have Bob removed from it?

So, in essence: there is a table with a text field. Each row has many different names. I wish to remove all instances of "Bob", but keep the rest as is.

Any example code would be greatly appreciated.

Thanks in advance.
 
look into charindex() and patindex() functions and then you can use replace() function to replace bob with nothing...

-DNG
 
you can use replace
Code:
declare @v varchar(666)
select @v ='Joe, Bob, Mike'

select replace(@v,'Bob,','')
but it's not perfect see below
Code:
declare @v varchar(666)
select @v ='Joe, JoeBob, Mike'

select replace(@v,'Bob,','')

Denis The SQL Menace
SQL blog:
Personal Blog:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top