Print Page | Close Window

Woe is me... replace words in db

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3720
Printed Date: 29 March 2026 at 11:56pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Woe is me... replace words in db
Posted By: Nischint
Subject: Woe is me... replace words in db
Date Posted: 21 June 2003 at 11:19am

Recently, I decided to change the name of a directory, from stuff to info. So all files within the stuff folder, were moved to the info folder.

That's when the problems started.

I have some 100 records in a DB which may or may not contain the line <a href="../stuff/default.asp">Link</a> .

How do I change all occurences of such links into <a href="../info/default.asp">Link</a> ?

Do I have to download the database, and physically change all 100 records? Do I update each and every record and replace stuff with info?

I see either as being too much work. Isn't there any other solution??

Maybe creating a constant that every instance of ../stuff/ be replaced by ../info/???



-------------
A better idiot

http://www.jamlikethat.com">Jam Like That



Replies:
Posted By: Mart
Date Posted: 21 June 2003 at 2:27pm
replace(rs("link"), "stuff", "info") that should help...


Posted By: b_bonnett
Date Posted: 21 June 2003 at 3:44pm
Do While Not rsWhatever.EOF
strLink = rsWhatever.Fields("link")
strLink = Replace(strLink, "../stuff", "../info")
rsWhatever.Fields("link") = strLink
rsWhatever.Update
rsWhatever.MoveNext
Loop

Hope this helps,
Blair

-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch


Posted By: MorningZ
Date Posted: 22 June 2003 at 3:23am

looking at a bigger project...

i am about to re-release my site and it'll have tons of "bad" links in it....

so i am going to use a custom 404 error page ("page not found" error) and look in the page for pages that i know will be accessed... and have a huge select statement to redirect to the right page

hopefully it works out



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: ljamal
Date Posted: 22 June 2003 at 10:04am
Originally posted by b_bonnett b_bonnett wrote:

Do While Not rsWhatever.EOF
strLink = rsWhatever.Fields("link")
strLink = Replace(strLink, "../stuff", "../info")
rsWhatever.Fields("link") = strLink
rsWhatever.Update
rsWhatever.MoveNext
Loop

Hope this helps,
Blair


Why run a loop? Or even run via ASP or VBScript?
Just run the query from the database. The syntax is:

update tablename set fieldname = Replace(fieldname, text to replace, replacement text)

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Nischint
Date Posted: 22 June 2003 at 3:39pm

Blair, your suggestion is great, but I'm looking for a more permanent solution, and I want to be able to make the changes within the database itself.

ljamal, your way works the best. The db itself is quite large, so I can't download it, make the change and reupload it, without getting lots of problems and errors. Is there any way I can create an asp page with this query?? I tried it, but I got it wrong, it just changed all the records to the fieldname for some reason. Here's the sql:

sql = "update tblLinks set strLinks= Replace(strLinks, ../stuff/, ../info/)"

What could be the error??



-------------
A better idiot

http://www.jamlikethat.com">Jam Like That


Posted By: michael
Date Posted: 22 June 2003 at 3:47pm

sql = "update tblLinks SET strLinks=Replace(strLinks,'../stuff/','../info/')"

If you want to keep stuff and info as a variable then you gotta sep the sql query.



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: Nischint
Date Posted: 22 June 2003 at 4:03pm
sql = "update tblLinks SET strLinks = Replace(strLinks,'../stuff/','../info/')"

doesn't work. It throws up this error:

Undefined function 'Replace' in expression.

What gives??

-------------
A better idiot

http://www.jamlikethat.com">Jam Like That


Posted By: ljamal
Date Posted: 22 June 2003 at 4:25pm
I don't think Access has a replace function
so you will have to do it the hard way and use the loop as suggested earlier. Be sure that your recordset only include the links that need to be updated rather than looping through everything in the table.

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: Nischint
Date Posted: 22 June 2003 at 5:39pm
I need to run this page just once, and my work will be complete. There has got to be some way to do this in ASP.

Come on guys, help me out here!!

-------------
A better idiot

http://www.jamlikethat.com">Jam Like That


Posted By: b_bonnett
Date Posted: 22 June 2003 at 10:53pm
Originally posted by Nischint Nischint wrote:

Blair, your suggestion is great, but I'm looking for a more permanent solution, and I want to be able to make the changes within the database itself.



Ummmmm... this IS permanent! As long as you use the Update command (i.e. rsWhatever.Update) the change is stored in the database. Trust me, it works, I have used this to get me out of this problem before .

Blair

-------------
Webmaster, http://www.planegallery.net/ - The Plane Gallery
Greetings From Christchurch



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net