日期:2014-05-18 浏览次数:20942 次
declare @tb table (s varchar(1000)) insert into @tb select '<P> </P> <P>123 </P> <P>12 <IMG height=25 src="/WebSite/upfiles/2721.gif" width=50 border=0> </P> <P>312 </P> <P>312' select substring(s,patindex('%src="%',s),charindex('"',s,patindex('%src="%',s)+5)-(patindex('%src="%',s))+1) from @Tb where s like '%src="%'
------解决方案--------------------
if object_id('tempdb.dbo.#') is not null drop table # create table # (c varchar(8000)) insert # select '<P> src= </P> <P>123 </P> <P>12 <IMG height=25 src="/WebSite/upfiles/2721.gif" width=50 border=0> </P> <P>312 </P> <P>312 </P> <P> </P>' insert # select '<P> src=" </P> <P>123 </P> <P>12 <IMG height=48 src="/WebSite/upfiles/2696.gif" width=40 border=0> </P> <P>312 </P> <P>312 </P> <P> </P>' insert # select '<P> </P> <P>123 </P> <P>12 </P> <P>312 </P> <P>312 </P> </P>' select * from # select substring(c, charindex('src=',c,charindex('<IMG',c)), charindex('"',c,charindex('src=',c,charindex('<IMG',c))+5)-charindex('src=',c,charindex('<IMG',c))+1) from # where charindex('src=',c,charindex('<IMG',c))>0 /* src="/WebSite/upfiles/2721.gif" src="/WebSite/upfiles/2696.gif" */
------解决方案--------------------
create table # (news_content varchar(8000)) insert # select '<P> </P> <P>123 </P> <P>12 <IMG height=25 src="/WebSite/upfiles/2721.gif" width=50 border=0> </P> <P>312 </P> <P>312 </P> <P> </P> ' insert # select '<P> </P> <P>123 </P> <P>12 <IMG height=48 src="/WebSite/upfiles/2696.gif" width=40 border=0> </P> <P>312 </P> <P>312 </P> <P> </P> ' insert # select '<P> </P> <P>123 </P> <P>12 </P> <P>312 </P> <P>312 </P> </P>' go select replace(substring(news_content,charindex('src="',news_content),charindex('.gif"',news_content) - charindex('src="',news_content)+5),'"','') as src from # where charindex('src="',news_content) > 0 if object_id('tempdb.dbo.#') is not null drop table # /* src --------- src=/WebSite/upfiles/2721.gif src=/WebSite/upfiles/2696.gif */