select replace(字段名,'<img ****>****</img>','你要的字符') from tb
try declare @str varchar(8000) set @str = '<img adfadfagsdg****>**adfagaaeyu23464457k**</img>' select @str as a into # select * from # where a like '%<img%>%</img>%' a ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- <img adfadfagsdg****>**adfagaaeyu23464457k**</img>(所影响的行数为 1 行)
--> 测试数据: #tb if object_id('tempdb.dbo.#tb') is not null drop table #tb go create table #tb (id varchar(100) ) insert into #tb select 'sgddg<img adfadfagsdg****>**adfagaaeyu23464457k**</img>eg'select stuff(id,charindex('<img',id),charindex('</img>',id)+6-charindex('<img',id),'要替换的字符') from #tb sgddg要替换的字符eg
declare @str varchar(8000)
set @str = '<img adfadfagsdg****>**adfagaaeyu23464457k**</img>'
select @str as a into #
select * from # where a like '%<img%>%</img>%'
a
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<img adfadfagsdg****>**adfagaaeyu23464457k**</img>(所影响的行数为 1 行)
if object_id('tempdb.dbo.#tb') is not null drop table #tb
go
create table #tb (id varchar(100) )
insert into #tb
select 'sgddg<img adfadfagsdg****>**adfagaaeyu23464457k**</img>eg'select
stuff(id,charindex('<img',id),charindex('</img>',id)+6-charindex('<img',id),'要替换的字符')
from #tb
sgddg要替换的字符eg
SELECT REPLACE(@str
,SUBSTRING(@str,CHARINDEX('<img',@str),CHARINDEX('</img>',@str)-CHARINDEX('<img',@str)+6)
,'xxx'
)
----方法二:
SELECT STUFF(@str ,CHARINDEX('<img',@str),CHARINDEX('</img>',@str)-CHARINDEX('<img',@str)+6,'xxx')--------------------------------
aaxxxbb(1 row(s) affected)
----------------------------------
aaxxxbb(1 row(s) affected)