這樣呢 ??
create table table1(Addrcode char(12),ID int)
insert table1 select '110101001001',Null
insert table1 select '110101001003',Null
insert table1 select '110101001001',Null
insert table1 select '110101001002',Null
GO
Alter Table table1 Add IDD Int Identity(1,1)
GO
Update table1 Set ID=IDD
GO
Alter Table table1 Drop Column IDD
GO
Select * From table1
GO
Drop Table table1
--Result
/*
Addrcode ID
110101001001 1
110101001003 2
110101001001 3
110101001002 4
*/

解决方案 »

  1.   

    这样的update要求在Addrcode加聚集索引
      

  2.   

    也就是说,要求表的存储是按照Addrcode排序
      

  3.   

    create table table1(Addrcode char(12),ID int)
    insert table1 select '110101001001',Null
    insert table1 select '110101001003',Null
    insert table1 select '110101001001',Null
    insert table1 select '110101001002',Null
    GO
    Alter Table table1 Add IDD Int Identity(1,1)
    GO
    Update A Set ID=(Select Count(*) From table1 Where Addrcode=A.Addrcode And IDD<=A.IDD) From table1 A
    GO
    Alter Table table1 Drop Column IDD
    GO
    Select * From table1
    GO
    Drop Table table1
    --Result
    /*
    Addrcode ID
    110101001001 1
    110101001003 1
    110101001001 2
    110101001002 1
    */