qadabcd (1werwe)
adfabcd (好1df)
avabcd  (wew3r231df)
qaabcd (/1werwe)
ssabcd (we好1df)
sdfabcd  (fwerwew3r231df)查询后qad
adf
av
...

解决方案 »

  1.   


    declare @t table (col varchar(30))
    insert into @t
    select 'qadabcd (1werwe)' union all
    select 'adfabcd'select left(col,charindex('abcd',col)-1) from @t
    /*
    qad
    adf
    */
      

  2.   


    declare @t table (col varchar(30))
    insert into @t
    select 'qadabcd (1werwe)' union all
    select 'adfabcd (好1df)' union all
    select 'avabcd (wew3r231df)' union all
    select 'qaabcd (/1werwe)' union all
    select 'ssabcd (we好1df)' union all
    select 'sdfabcd (fwerwew3r231df)' union all
    select 'aa'
    --先判断是否存在abcd 免得没有abcd的时候报错
    select 
    case when charindex('abcd',col)>0 then
    left(col,charindex('abcd',col)-1) else col end as col 
    from @t
    /*
    col
    ------------------------------
    qad
    adf
    av
    qa
    ss
    sdf
    aa
    */