用游标 我以前用过的!!!
set @num=0(定义序号)
declare a_cursor scroll cursor for
select port_id(根据port_id与p_id相同的项置入序号)
from report_tab
where yy=left(@s_date,2)and mm=left(right(@s_date,4),2)
order by exprice desc(根据exprice 排序)
open a_cursor
fetch next from a_cursor
into @p_id
while @@fetch_status=0
begin
update report_tab
set num_exprice=@num
where yy=left(@s_date,2)and mm=left(righ(@s_date,4),2) and port_id=@p_id
fetch next from a_cursor
into @p_id
set @num=@num+1
end
CLOSE a_cursor