先执行alter table test add xh int 假设你的table 中aaa,bbb,ccc均为int型 然后执行存储过程,代码如下: create proc p_test as begin declare @a int,@b int ,@c int,@i int set @i = 1 declare c1 cursor for select aaa,bbb,ccc from test order by aaa open c1 fetch next from c1 into @a,@b,@c while @@fetch_status =0 begin update test set xh =@i where aaa= @a and bbb=@b and ccc=@c set @i = @i + 1 fetch next from c1 into @a,@b,@c end end
update test set xh = (select count(*) from test a where a.aaa>=test.aaa)以上AAA有重复将有并列序号
如果你只想对AAA进行处理那就好办了,存储过程改一下就可以了,如下:create proc p_test as begin declare @a int,@b int ,@c int,@i int set @i = 1 declare c1 cursor for select distinct aaa from test order by aaa open c1 fetch next from c1 into @a while @@fetch_status =0 begin update test set xh =@i where aaa= @a set @i = @i + 1 fetch next from c1 into @a end end试一下,肯定可以的
假设你的table 中aaa,bbb,ccc均为int型
然后执行存储过程,代码如下:
create proc p_test
as
begin
declare @a int,@b int ,@c int,@i int
set @i = 1
declare c1 cursor for select aaa,bbb,ccc from test order by aaa
open c1
fetch next from c1 into @a,@b,@c
while @@fetch_status =0
begin
update test set xh =@i where aaa= @a and bbb=@b and ccc=@c
set @i = @i + 1
fetch next from c1 into @a,@b,@c
end
end
as
begin
declare @a int,@b int ,@c int,@i int
set @i = 1
declare c1 cursor for select distinct aaa from test order by aaa
open c1
fetch next from c1 into @a
while @@fetch_status =0
begin
update test set xh =@i where aaa= @a
set @i = @i + 1
fetch next from c1 into @a
end
end试一下,肯定可以的