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

Replace if target is in a set 1

Status
Not open for further replies.

SarasotaIT

IS-IT--Management
Mar 25, 2003
23
US
I have a very large table that I am trying to replace text in. I would like to design, using SQL, a query that will replace a string with a new value only if that string is part of a pre-specified group of values. For instance: In the CODE field, replace all the ocurrences of: 543, 545, 548, and 550 with the new value: GV. (There exists only one value per record.) I am just trying to minimize the find and replace process since I need to do this for about 100 values. THANKS MUCH IN ADVANCE!!
Terry
 
For just a few values, you can use SQL like
Code:
   UPDATE tbl SET fld = 'GV'
   WHERE fld IN ('543','545',548',550')
If you have many such replacements, I would build a separate table like this

tblReplace
Code:
OldValue    NewValue
   543          GV
   545          GV
   548          GV
   550          GV
Then use code like
Code:
   UPDATE tbl INNER JOIN tblReplace As R
          ON tbl.fld = R.OldValue
   SET fld = R.NewValue
 
Thanks, Golom! Worked like a charm!! I am using your first suggestion, but the next time we run these conversions, I will use your second sugg. Thanks again for saving my hide! :)
Terry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top