Groups | Blog | Home
all groups > sql server programming > april 2005 >

sql server programming : find and replace


Aaron
4/3/2005 11:06:32 PM
how do i write a query that will go through all the rows of a text field and
replace the search word with a new word.
like the find and replace feature in MS Access

REPLACE "ABC" WITH "CBS" IN DBTABLE.DBTEXT

Thanks,

Aaron

Aaron
4/4/2005 12:43:03 AM
Could you give me an example?


[quoted text, click to view]

Hari Prasad
4/4/2005 1:19:08 AM
Hi,

Use Update statement with Replace function in SET clause. This will work out
if ur data type is
Varchar/Char/Nchar,Nvarchar.

Thanks
Hari
SQL Server MVP

[quoted text, click to view]

Uri Dimant
4/4/2005 9:54:04 AM
Aaron
CREATE TABLE #Test
(
col VARCHAR(10)
)
INSERT INTO #Test VALUES ('FDABC')

UPDATE #Test SET col=REPLACE(col,'ABC','CBS')
---or if you know the start point and length of the string
UPDATE #Test SET col=STUFF(col,3,3,'CBS')


SELECT * FROM #Test





[quoted text, click to view]

AddThis Social Bookmark Button