declare @s varchar(8000)
set @s =  '<input   type="image"   height="92"   width="120"   src="/test/image/hoho.jpg"   src="/test/image/asd.jpg"/> '
select 
substring(@s,charindex('src="',@s)+5,charindex('.jpg',@s) - charindex('src="',@s) - 1)/*
-----------------------
/test/image/hoho.jpg(所影响的行数为 1 行)
*/

解决方案 »

  1.   


    select substring(right(info,len(info)-charindex('src="',info)-4),1,charindex('"',right(info,len(info)-charindex('src="',info)-4))-1) from 表名
      

  2.   

    declare @s table(col varchar(8000))
    insert  @s select   '<input   type="image"   height="92"   width="120"   src="/test/image/hoho.jpg"   src="/test/image/asd.jpg"/> '
    select 
    substring(col,charindex('src="',col)+5,charindex('.jpg',col) - charindex('src="',col) - 1) as col
    from @s/*
    col
    -----------------------
    /test/image/hoho.jpg(所影响的行数为 1 行)
    */
      

  3.   

    楼上上的大哥(所影响的行数为 2 行)服务器: 消息 536,级别 16,状态 3,行 1
    向 substring 函数传递了无效的 length 参数。无枪狙击手大哥
    如果我的格式gif,bmp,png都包括呢?
    还有
    insert  @s select   '<input   type="image"   height="92"   width="120"   src="/test/image/hoho.jpg"   src="/test/image/asd.jpg"/> '
    select后面这个不是固定的啊,我怎么写才好呢?
      

  4.   

    出现了向   substring   函数传递了无效的   length   参数。 
      

  5.   


    declare 
      @s varchar(200),
      @begin int,
      @end int
    select @s = '<p> <input   type="image"   height="92"   width="120"   src="/test/image/hoho.jpg"   src="/test/image/asd.jpg"/> ` </p> '
    select @begin = CHARINDEX('src="/',@s)
    select @end = CHARINDEX('"   src="/test/image/asd.jpg',@s)
    --print @begin
    --Print @end
    print substring(@s,CHARINDEX('src="',@s) + 5,@end-@begin - 5)主要用到 substring 和 CHARINDEX
      

  6.   

    不是关键我那不是例子吗
    假如我没有那行数据
    那select   @s   =   ' <p>   <input       type="image"       height="92"       width="120"       src="/test/image/hoho.jpg"  
    这个不就败了吗。
      

  7.   

    declare @s table(col varchar(8000))
    insert  @s select   '<input   type="image"   height="92"   width="120"   src="/test/image/hoho.jpg"   src="/test/image/asd.jpg"/> 'insert  @s select   '<input   type="image"   height="92"   width="120"   src="/test/images/hoho.png"   src="/test/image/asd.jpg"/> 'select 
    substring(col,charindex('src="',col)+5,charindex('"',col,charindex('src="',col)+5) - charindex('src="',col)-5) as col
    from @s/*
    col              
    --------------------------
    /test/image/hoho.jpg
    /test/images/hoho.png(所影响的行数为 2 行)
    */