select substring(字段名,case when patindex('%命中词%',字段名)<=100 then 1 else patindex('%命中词%',字段名)-100 end,patindex('%命中词%',字段名)+100+len('命中词'))
from 表

解决方案 »

  1.   

    --上面的还要改一下:declare @tj varchar(100)
    set @tj='%拉萨%'    --设置要查询的关键字select substring(字段名,case when patindex(@tj,字段名)<=100 then 1
    else patindex(@tj,字段名)-100 end,patindex(@tj,字段名)+100+4)
    from 表
    where 字段名 like @tj
      

  2.   

    --例子:
    declare @t table(a varchar(8000))
    insert into @t
    select '啊;圣诞节法律;按时搭街坊;撒旦解放了;按时解放;决撒了;解放;按时搭街坊;'
    union all select 'sa;dkjfpoawuerpo安康搭街坊;拉萨酱豆腐;喀什搭街坊;asdkf;asl jfas;djf;sadj;似的;'
    union all select 'asd撒旦机撒旦机;撒旦机撒旦艰苦可是地方艰苦的;毫磅批 sa;dkjfpoawuerpo安康搭街坊;拉萨酱豆腐;喀什搭街坊;asdkf;asl jfas;djf;sadj;似的;'declare @tj varchar(100)
    set @tj='%拉萨%'select substring(a,case when patindex(@tj,a)<=100 then 1
    else patindex(@tj,a)-100 end,patindex(@tj,a)+100+4)
    from @t
    where a like @tj