Wednesday, March 28, 2012

Replacing all occurrences of a string in a VARCHAR column?

Hi All
I have table Tab1 with a column Col1 of data type VARCHAR. I want to
replace every "Kop " string in that column with "HY". Is there an easy way t
o
do this. Below is an example with column Col1 with 2 rows of data:
Col1
---
J Dixion
K Kop
I got some helpful scripts on replacing a string within a TEXT column last
time like the one below. I have tried those scripts on other data types of
data like VARCHAR and it did not work.
http://aspfaq.com/show.asp?id=2445
Thank you in advance.UPDATE tab1
SET col1 = REPLACE(col1,'Kop','HY')
WHERE col1 LIKE '%Kop%' ;
David Portas
SQL Server MVP
--|||Thank you Dave. It got the job. Thank you once again.
--
5 years experience with SQL Server 2000 and SAP BW/SEM
"David Portas" wrote:

> UPDATE tab1
> SET col1 = REPLACE(col1,'Kop','HY')
> WHERE col1 LIKE '%Kop%' ;
> --
> David Portas
> SQL Server MVP
> --
>
>

No comments:

Post a Comment