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 2005 Forums
 Transact-SQL (2005)
 Updating a substring

Author  Topic 

Jim Beam
Posting Yak Master

137 Posts

Posted - 2010-10-05 : 07:32:52
Hi all,

I need to update the following data in tbldefinemessagetext.textstring so any instance of 'http://m.mirror.co.uk/alerts' changes to 'http://www.telegraph.co.uk/sport/', ie

Access for 24hrs at http://m.mirror.co.uk/alerts becomes
Access for 24hrs at http://www.telegraph.co.uk/sport/

Cheers,

Jim

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-05 : 07:38:52
update table
select column = replace(column,'searchstring','newstring')
where column like '%searchstring%'



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-05 : 07:40:38
[code]
declare @tbl as table(val varchar(200))
insert into @tbl
select 'Access for 24hrs at http://m.mirror.co.uk/alerts'
union
select 'Access for 24hrs at http://abc.mirror.co.uk/alerts'

update @tbl set val=
replace(val,'http://m.mirror.co.uk/alerts','http://www.telegraph.co.uk/sport/')
from @tbl

select * from @tbl
[/code]

PBUH

Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2010-10-05 : 07:41:27
quote:
Originally posted by webfred

update table
select column = replace(column,'searchstring','newstring')
where column like '%searchstring%'



No, you're never too old to Yak'n'Roll if you're too young to die.



Is there a need for the where clause?

PBUH

Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-10-05 : 09:50:52
quote:
Originally posted by Sachin.Nand

quote:
Originally posted by webfred

update table
select column = replace(column,'searchstring','newstring')
where column like '%searchstring%'



No, you're never too old to Yak'n'Roll if you're too young to die.



Is there a need for the where clause?

PBUH




Without where clause each row will be updated.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -