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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String replacement updates

Status
Not open for further replies.

rrhandle

Programmer
Dec 26, 2001
193
US
I am frequently finding myself have to replace text in a table(s). I know there must be a better way to do this, so I am asking for suggests.

EXAMPLE: Replace 'TH-' in the ABBR_1 field with 'TMF-'

Table name: ABBR
Code:
ABBR_1    PRICE    Desc
------    -----    ----
TH-34     12.34    3" thermaform
TH-12     15.45    1" thermaform
ER-T      12.00    T-Erector
Thank for the suggestions.

--Rob

 
First, you should run a 'select' query to make sure it's right.

Code:
Select Replace(Abbr_1, 'TH-', 'TMF-') As NewValue,
       *
From   Abbr

If it's right, then...
Code:
Update Abbr
Set    Abbr_1 = Replace(Abbr_1, 'TH-', 'TMF-')



-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
something like:

Code:
update ABBR
   set ABBR_1 = replace( ABBR_1, 'TH-', 'TMF-' )
[gray] where ABBR_1 like 'TH-%'[/gray]

the where clause is optional...it may speed up your query.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Remember that you need to be careful doing this (which is why running a select first was recommended by cLFlaVA) doing a global replace can break things if the pattern shows up on records you don't want to change.

Questions about posting. See faq183-874
Click here to help with Hurricane Relief
 
Pfffft. I like SQL Sister, so I didn't bother correcting her.

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top