select substring(news_content,charindex('src="',news_content),charindex('"',news_content) - charindex('src="',news_content)- 5) as src
from ta

解决方案 »

  1.   

    select substring(news_content,charindex('src="',news_content),charindex('"',news_content) - charindex('.gif"',news_content)) as src
    from ta
      

  2.   

    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)+5,charindex('"',s,patindex('%src="%',s)+5)-(patindex('%src="%',s)+5)) from @Tb
    where s like '%src="%'/WebSite/upfiles/2721.gif
      

  3.   

    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="%'src="/WebSite/upfiles/2721.gif"
      

  4.   

    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 replace(substring(s,patindex('%src="%',s),charindex('"',s,patindex('%src="%',s)+5)-(patindex('%src="%',s))+1),'"','') as s from @Tb
    where s like '%src="%'src=/WebSite/upfiles/2721.gif
      

  5.   

    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"
    */
      

  6.   


    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*/