我现在A表的字段里有01 02 10 11 12 100 101这些
我现在要把字段都变成3位 不足的补0
变成001 002 010.
怎么弄 谢谢

解决方案 »

  1.   

    update tb set col=right('000'+col,3)
      

  2.   

    if object_id('tempdb..#')is not null drop table #
    go
    create table # (col varchar(10))
    insert # select '01' union all select '02'
                                 union all select '10'
                                 union all select '11'
                                 union all select '12'
                                 union all select '100'
                                 union all select '101'
    update # set col=right('000'+col,3)
    select * from #
    /*col        
    ---------- 
    001
    002
    010
    011
    012
    100
    101(影響 7 個資料列)*/
      

  3.   

    if object_id('tempdb..#')is not null drop table #
    go
    create table # (col varchar(10))
    insert # select '01' union all select '02'
                                 union all select '10'
                                 union all select '11'
                                 union all select '12'
                                 union all select '100'
                                 union all select '101'
    select right('000'+col,3) from # --查詢
    /*col        
    ---------- 
    001
    002
    010
    011
    012
    100
    101(影響 7 個資料列)*/
      

  4.   

    /*
    /*我现在A表的字段里有01 02 10 11 12 100 101这些 
    我现在要把字段都变成3位 不足的补0 
    变成001 002 010. 
    怎么弄 谢谢*/
    declare @t table(col001 varchar(10))
    insert @t select '01'
    union all select '02'
    union all select '10'
    union all select '11'
    union all select '12'
    union all select '100'
    union all select '101'select * from @tselect right('000'+col001,3) from @t/*
    所影响的行数为 7 行)col001     
    ---------- 
    01
    02
    10
    11
    12
    100
    101(所影响的行数为 7 行)       
    ------ 
    001
    002
    010
    011
    012
    100
    101(所影响的行数为 7 行)
    */
      

  5.   

    update tb set col=right('000'+col,3)
      

  6.   

    update 表名
        set 列 = right('00' + 列,3)