select PARTNO,rank() over(partition by PARTNO order by SEQUENCE_NO) as SEQUENCE_NO
from tablename
order by PARTNO,SEQUENCE_NO

解决方案 »

  1.   

    alter table TableName add id int identity
    go
    update A set SEQUENCE_NO=(select count(*) from TableName where  PARTNO=A.PARTNO and id<=A.id) from TableName A
    go
    alter table tableName deop id
    go
      

  2.   

    不能直接update可用j9988(j9988)的方法或删除再添加合规则的记录
      

  3.   

    declare @C_PARTNO varchar(3)
    declare @C_SEQUENCE_NO varchar(1)
    declare @i_no  Int
    set @i_no = 0
    declare cur_Select cursor for 
    select distinct  PARTNO from tableName 
     bein trans
    fetch next from cur_Select into @C_PARTNOdo while @@fetch_status =0 
    begin    set @i_no = @i_no + 1 
       update SEQUENCE_NO = @i_no + 1 where PARTNO =@C_PARTNO
       fetch next from cur_Select into @C_PARTNOend 
     close cur_Select
     deallocate cur_Selectcommit trans