原数据列:
编号
1
2
3
.
.
.
10
11
.
.
100
101
.
.
我想让该列变为五位,不满五位前面自动填0,能不能用简单的语句实现.
结果如下:编号
00001
00002
00003
.
.
.
00010
00011
.
.
00100
00111
.
.
.注:该列为varchar型先谢了.

解决方案 »

  1.   

    create table #(num varchar(10))
    insert into # select top 10 id from sysobjectsupdate # set num=right(100000+num,5) select * from #
      

  2.   

    update tablename set 编号=right(100000+cast(编号 as int),5)
      

  3.   

    declare @t table(编号 varchar(10))
    insert @t
    select '1' union all
    select '2' union all
    select '3' union all
    select '4' union all
    select '5'update @t set 编号 = right('0000' + rtrim(编号),5)select * from @t
      

  4.   

    hoho 都正解了  right()    ……——……