0019 + 1 = 00200019是字符类型在sql里怎么实现?越简单越好

解决方案 »

  1.   

    select right('000'+cast(cast(0019 as int) + 1 as varchar),4)/*
             
    -------- 
    0020(所影响的行数为 1 行)
    */
      

  2.   

    select right('0000'+ltrim('0019' + 1),len('0019'))
      

  3.   

    drop table tb;
    CREATE TABLE tb(Id varchar(4));
    insert into tb(Id)
    select
    '0001' union all select
    '0002' union all select
    '0003' union all select
    '0004' union all select
    '0005' union all select
    '0006' union all select
    '0007' union all select
    '0008' union all select
    '0009' union all select
    '0010' union all select
    '0011' union all select
    '0012' union all select
    '0013' union all select
    '0014';select * from tb;update tb set id=right('0000'+convert(varchar(4),id+1),4);select * from tb;