Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 find and replace

Author  Topic 

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2004-12-12 : 01:58:46
Hi I have a table items with a description field --
Is there anyway I can do find and replace to replace anywhere in description field where it says link.asp and change to item.asp?

Kristen
Test

22859 Posts

Posted - 2004-12-12 : 03:47:05
SELECT REPLACE(MyColumn, 'link.asp', 'item.asp')
FROM MyTable

or maybe:

UPDATE MyTable
SET MyColumn = REPLACE(MyColumn, 'link.asp', 'item.asp')

Kristen
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2004-12-12 : 03:56:17
and this will only replace where it says link.asp and not the whole field?
Go to Top of Page

esthera
Master Smack Fu Yak Hacker

1410 Posts

Posted - 2004-12-12 : 04:23:14
I tried this:

UPDATE items
SET description = REPLACE(description, 'link.asp', 'item.asp') where itemid=450

and got
Server: Msg 8116, Level 16, State 1, Line 1
Argument data type ntext is invalid for argument 1 of replace function.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-12 : 10:09:36
You can't use replace on a blob.
You will have to split it into 8000 char chunks and do an updatetext on the field.
You can use like to find the entries to update.

I might do a solution for this later as it's been asked a number of times.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-12-13 : 00:23:23
http://www.nigelrivett.net/SQLTsql/ReplaceText.html

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -