|
楼主
楼主 |
发表于 2004-9-15 14:56:55
|
只看该作者
看看此帖有无简便解法
一个表中有sex,age,name……字段,现在,需要将sex,age均相同的人识别为一组,并建立组号gid,gid依次累加。(即添加gid)
SQL server中的存储过程实现太复杂了
[code:9a20f]declare @sex char(2), @age char(2),
@i int
declare cur_group cursor
for
select sex,age from tbl group by sex, age
for read_only
open cur_group
fetch next from cur_group into @sex, @age
set @i = 1
while @@fetch_status = 0
begin
update tbl set gid = @i where sex=@sex and age=@age
fetch next from cur_group into @sex, @age
set @i = @i + 1
end
close cur_group
deallocate cur_group [/code:9a20f] |
|