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!

Replace all string

Status
Not open for further replies.

znet

Programmer
Aug 23, 2004
41
CA
Hi,
Does anybody know how to replace a string in a column (several hundreds records), for ex, I want replace all the string ('cat') contained in the column COL1 of table 'Tab' with the new string ('dog'). Can I only use SQL to do this.

Thanks in advance
 
Yes, SQL is the best (and only) way to do this.

[tt]
UPDATE Tab
SET COL1 = 'dog'
WHERE COL1 = 'cat'
[/tt]

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
I think CLFlava has maybe misunderstood - if the word cat can be anywhere in the field I think you need REPLACE.

BOL reference

REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )

Arguments

'string_expression1'

Is the string expression to be searched. string_expression1 can be of character or binary data.

'string_expression2'

Is the string expression to try to find. string_expression2 can be of character or binary data.

'string_expression3'

Is the replacement string expression string_expression3 can be of character or binary data.

DBomrrsm

[bandito] [blue]DBomrrsm[/blue] [bandito]
 
Thanks clFlaVA, your response so fast. I am sorry I haven't said my question clearly. I want to replace sub strings in all the records of a column, for ex: the record: ' This is a cat' should be changed to ' This is a dog',...
 
Gotcha. My mistake.

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top