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
 SQL Server Development (2000)
 SQL to Replace part of an html string

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-12-08 : 08:21:24
Mark writes "Hi there,

I have multiple rows in a table which represents HTML news items. I need to take an existing image path and replace it with a new one whilst leaving the rest of the HTML in tact.

Can anyone help me do this.

Here is an example:

<h5>Future to launch Magazine</h5><img src="/CS/User/Images/Magazine.jpg" border=0>
Future Publishing in the UK has launched a new customer magazine.

On 25 August the quarterly publication was launched, the growing contract magazine of X ltd.

In this case I need to replace "/CS/User/Images/Magazine.jpg" WITH "/BS/User/Assets/Images/Magazine.jpg"

The HTML will then read as follows

<h5>Future to launch Magazine</h5><img src="/BS/User/Assets/Images/Magazine.jpg" border=0>
Future Publishing in the UK has launched a new customer magazine.

On 25 August the quarterly publication was launched, the growing contract magazine of X ltd.


I need to do this for multiple rows. Any help would be greatly appreciated.

Regards
Mark"

jhocutt
Constraint Violating Yak Guru

385 Posts

Posted - 2005-12-08 : 08:39:03
create table #tmp ( t1 varchar(2000) )
insert into #tmp values ('<h5>Future to launch Magazine</h5><img src="/CS/User/Assets/Images/Magazine.jpg" border=0>')

select * from #tmp
update #tmp set t1 = replace(t1, '/CS/User/Images/Magazine.jpg', '/BS/User/Assets/Images/Magazine.jpg')
select * from #tmp


"God does not play dice" -- Albert Einstein
"Not only does God play dice, but he sometimes throws them where they cannot be seen."
-- Stephen Hawking
Go to Top of Page
   

- Advertisement -