一张表A a字段长度不固定,长度为20、22、截取后六位,其他的不截取,
最好用一个公式或者存储过程写

解决方案 »

  1.   


    declare @a varchar(200)
    set @a = '1234567890-abacadfdsf'
    select right(@a,6)
    select substring(@a,len(@a)-5,6)
    两个都可以。
      

  2.   

    DECLARE @str VARCHAR(100)
    SET @str = 'asdfasdfasdfasdfasdfasdf'
    SELECT RIGHT(@str,6)
    SELECT SUBSTRING(@str,LEN(@str)-5,6)------
    dfasdf(1 row(s) affected)
    ------
    dfasdf(1 row(s) affected)
      

  3.   

    SELECT STUFF('AAAAAAAAA',1,LEN('AAAAAAAAA')-6,'')--这样也可以,不过RIGHT和SUBSTRING最保险,如果小于6位不会出错
      

  4.   

    create table t(team varchar(1))
    insert into t values('a')
    insert into t values('b')
    insert into t values('c')
    insert into t values('d')
    go  select * from t
    select m.team , n.team from t m, t n where m.team < n.team order by m.team  ------------------a
    b
    c
    d
    ----》a b
    a c
    a d
    b c
    b d
    c d