如题所示,
在一个字段上取不是右边5位的数据,其中右边5位都是以S+四个数字组成,

AL1024149S0148      
AL1024349S0148      
AL2254149S0146      
AL3022448S0147      
结果为
AL1024149
AL1024349
AL2254149
AL3022448
谢谢!

解决方案 »

  1.   

    select left(col , charindex('s',col) - 1) from tb where charindex('s',col) > 0
      

  2.   


    --如果确定右边五个不要,可直接如下
    select left(col , len(col) - 5) from tb when len(col) > 5
      

  3.   

    select * from tb where right(col,5) not like 's%'
    select * from tb where charindex('s',right(col,5))!=1
    select * from tb where col not like '%s[0-9][0-9][0-9][0-9]'
    ...
    写法太多,不一一写了.
      

  4.   

    select substring(1,len(字段)-5)
    如果要处理的字段中有null或则有长度小于5的加上case when 语句
    有分给么?
      

  5.   

    好像理解错了.楼主是要以最后五位以s打头4个数字结尾的作过滤,还是将字段显示时去掉后面的部分?
    如果是前者,那就是我上一贴写的.如果是后者,那么稍改动.select left(col,len(col)-5) from tb where right(col,5) like 's%'
    select stuff(col,len(col)-5,5,'') from tb where charindex('s',right(col,5))=1
    ...
    组合出来又有n种..