select right('000'+str(ID),3) from 表

解决方案 »

  1.   

    select left('000',3-len(ID))+cast(ID as varchar(10)) from 表
      

  2.   

    select right(cast(1000+id as varchar),3) from 表
      

  3.   

    select right('000'+convert(varchar(5),ID),3) from 表
      

  4.   

    select right('000'+convert(varchar(5),ID),3) from 表
      

  5.   

    select right('00'+cast(id as varchar),3)  from Table
      

  6.   

    select id, 
    case 
    when  id <10  then '000'+cast( id as char)
    when  id < 100 then '00'+cast(id as char)
    when id < 1000 then '0'+ cast(id as char)
    end
     from table
      

  7.   

    cast和convert是什么意思?
    ------------------------------
    转换数据类型
    declare @i varchar(10)
    set @i = '0012'
    select cast(@i as int)    --将@i转换为int型select convert(int,@i)   --将@i转换为int型
      

  8.   

    详细帮助信息,请在SQL Server 2000联机帮助索引中分别输入cast、convert
      

  9.   

    select right( '000'+ rtrim(cast(id as char )),4) from  tablecast 和 convert 是用来做数据转换的