请问在存储过程中,我要生成一个编号,长度为5个字符,不足位的前面补0,如何将数字152,变为字符串"00152"?

解决方案 »

  1.   

    Select Right('00000'+Rtrim(152),5)
    Select Right('00000'+Rtrim(15),5)
    --結果
    00152
    00015
      

  2.   

    Declare @I Int
    Set @I=152
    Select Right('00000'+Rtrim(@I),5)
    Set @I=15
    Select Right('00000'+Rtrim(@I),5)
    Set @I=321
    Select Right('00000'+Rtrim(@I),5)
    --結果
    00152
    00015
    00321
      

  3.   

    declare @var int
    set @var=125
    select right(100000+@var,5)
    ---
    我一直这么用来着,没有找到更好的方法
     楼上的方法也可以,
      

  4.   

    select replace(str(152,5),' ','0')
      

  5.   

    '00000'+Rtrim(@I)的结果是什么啊?是00000152么?