M-001
自增到
M-999
我需要一个select写

解决方案 »

  1.   

    select 'M'+right('00'+RTRIM(number+1),3)
    from master..spt_values where number<999
    and type='p'/*
    -------
    M001
    M002
    M003
    M004
    M005
    M006
    M007
    M008
    M009
    M010
    M011
    M012
    M013
    ...
    M999
      

  2.   


    select 'M-'+right('00'+RTRIM(number+1),3)
    from master..spt_values where number<999
    and type='p'
      

  3.   

    看来我说错了
    我是需要M-001可以自增到M-990
    如果M-001就M-002
    M-002到M-003不是一下全部生存999
      

  4.   


    --这样?试试
    update tb set col='M-'+right('00'+rtrim(convert(int,replace(col,'M-',''))+1),3)
      

  5.   


    --select的话这样
    select col='M-'+right('00'+rtrim(convert(int,replace(col,'M-',''))+1),3) from tb
      

  6.   


    select 'M-'+max(cast(right(col,len(col)-2) as int)) as col
    from tb
      

  7.   

    7楼有问题!
    select 'M-'+right(1001+max(cast(right(col,len(col)-2) as int)),3) as col
    from tb
      

  8.   


    select 'M-'+right(1001+isnull(max(cast(right(col,len(col)-2) as int)),0),3) as col
    from tb