|
我上面写的有错,在2000里,这样写,只要你的表名,列名改回你的,就可以直接用的。
declare @tname varchar(50),@x int,@y int,@tscore float,@tming int,@z int,@m int
declare @tname1 varchar(50),@tscore1 float,@tming1 int,@tname2 varchar(50),@tscore2 float,@tming2 int
set @x=1
set @z=1
select @y=count(*) from dbo.testtable_mark
DECLARE authors_cursor SCROLL CURSOR FOR
SELECT * FROM dbo.testtable_mark
ORDER BY score desc
OPEN authors_cursor
while @x<=@y
begin
FETCH ABSOLUTE @x FROM authors_cursor
into @tname,@tscore,@tming
update dbo.testtable_mark
set 名次=@x
where [name]=@tname
set @x=@x+1
set @tname=''
end
while @z<=@y
begin
set @m=@z+1
FETCH ABSOLUTE @z FROM authors_cursor
into @tname1,@tscore1,@tming1
FETCH ABSOLUTE @m FROM authors_cursor
into @tname2,@tscore2,@tming2
if @tscore1=@tscore2
update dbo.testtable_mark
set 名次=@tming1
where [name]=@tname2
set @z=@z+1
end
CLOSE authors_cursor
DEALLOCATE authors_cursor
GO
|