棘手的问题
数据库结构如下:
凭证号 行数 .....
10
10
10
20
20
20
20
......
怎样才能使相同的凭证号的行数字段从1递增到最后一个记录
凭证号 行数 .....
10 1
10 2
10 3
20 1
20 2
20 3
20 4
......
问题点数:20、回复次数:6Top
1 楼lencon(深秋叙)回复于 2005-05-12 11:36:18 得分 4
我原来用VF做过财务软件
是单独将 凭证号为10的先SELECT 出来,再进行赋值 行数1 2 3Top
2 楼Open2ye(Open2ye)回复于 2005-05-12 13:01:07 得分 4
最简单的办法 。
先新建一个字段 把这个字段设为是自动增号的。
完成后就自己加上了。 (一定要新建一个)
再把原来的属性改回来
Top
3 楼Open2ye(Open2ye)回复于 2005-05-12 13:03:33 得分 4
不好意思,看错了 我以为是流水号
按 lencon 的方法就行.
Top
4 楼tdtjjiao(学习学习再学习)回复于 2005-05-12 13:17:48 得分 4
我用存储过程帮你帮一个。Top
5 楼tdtjjiao(学习学习再学习)回复于 2005-05-12 13:32:58 得分 4
测试数据
create table #t (pzid int Identity(1,1),pzNO int, could int)
insert #t (pzNO, could) values (10, 0)
insert #t (pzNO, could) values (10, 0)
insert #t (pzNO, could) values (10, 0)
insert #t (pzNO, could) values (20, 0)
insert #t (pzNO, could) values (20, 0)
insert #t (pzNO, could) values (20, 0)
go
create table #t1 (pzid1 int Identity(1,1),pzNO1 int)
insert #t1 (pzNO1) select pzNO from #t group by pzNO
declare @min int, @max int, @pzNO int, @min1 int, @max1 int, @i int
select @min=min(pzid1) from #t1
select @max=max(pzid1) from #t1
select @max
while @min <= @max
begin
set @i = 1
select @pzNO = pzNO1 from #t1 where pzid1 = @min
select * into #t2 from #t where pzno = @pzno
select @min1 = min(pzid) from #t2
select @max1 = max(pzid) from #t2
while @min1 <= @max1
begin
update #t set could = @i where pzid = @min1
set @i = @i + 1
set @min1 = @min1 + 1
end
drop table #t2
set @min = @min + 1
end
结果
select pzno, could from #t
pzno could
----------- -----------
10 1
10 2
10 3
20 1
20 2
20 3
drop table #t
drop table #t1
Top
6 楼jlanyi2003(江城浪子)回复于 2005-05-13 14:38:30 得分 0
多谢大家,我解决了Top




