ID原来是1,2,3,....
如何改成都是0001,0002,0003...

解决方案 »

  1.   

    查询的时候
    select right(10000+id,4) as id from tablename
      

  2.   

    Create Table TEST(ID Varchar(10))
    Insert TEST Select 1
    Union All Select 2
    Union All Select 3
    Union All Select 4
    GO
    Update TEST Set ID = Right(10000 + ID, 4)Select * From TEST
    GO
    Drop Table TEST
    --Result
    /*
    ID
    0001
    0002
    0003
    0004
    */
      

  3.   

    paoluo
    在哪里写这段代码?谢谢
      

  4.   

    在查詢分析器中,選擇你要更新的表所在的數據庫。然後執行Update TEST Set ID = Right(10000 + ID, 4)
      

  5.   

    Update TEST Set ID = Right(10000 + ID, 4)就这个了哈,楼主执行吧