原表 想这样做新表
单据号 小序号 单据号 小序号
1 NULL 1 1
1 NULL 1 2
1 NULL 1 3
2 NULL 2 1
2 NULL 2 2
3 NULL 3 1
3 NULL 3 2
3 NULL 3 3
3 NULL 3 4
。
。
。
单据号 小序号 单据号 小序号
1 NULL 1 1
1 NULL 1 2
1 NULL 1 3
2 NULL 2 1
2 NULL 2 2
3 NULL 3 1
3 NULL 3 2
3 NULL 3 3
3 NULL 3 4
。
。
。
select djh,xxh from tablename-- order by djh
for update of xxh
open abcdeclare @djh int
declare @xxh char(10)
declare @last_djh int
declare @j int
set @last_djh=0
set @j=1
while(0=0)begin
fetch next from abc into @djh,@xxh
if(@@fetch_status<>0)break
--print @djh
if(@last_djh!=@djh)begin
set @j=1
end
else begin
set @j=@j+1
end update tablename set xxh=@j where current of abc
set @last_djh=@djh
end
close abc
deallocate abc