中间有几个不懂的点,烦解答!
程序如下:
CREATE PROCEDURE lq_confirm
AS
BEGIN
--游标申明
declare @MyTestCursor Cursor
declare @KSH char(14)
declare @ZYDH char(2)
declare @YXDH char(4)
declare @JHCGS char(4)
----取出未录取满额专业的专业队列,及差额数
set @MyTestCursor=CURSOR for
(select yxdh,zydh,jhcgs from t_jhk where lqzt='0' )
open @MyTestCursor
fetch @MyTestCursor into @YXDH,@ZYDH,@JHCGS
while @@FETCH_STATUS=0
begin
if object_id('tempdb..#temp_zyk') is not null
begin
drop table #temp_zyk
end
else
begin
print 'not exists'
end
--先按成绩排序的考生放到到临时表
select ksh,zyh,ROW_NUMBER()over (order by tdcj desc,zyh,ksh asc) as zy_sort
into #temp_zyk
from t_zyk_new2
where yxdh=@YXDH
and zydh=@ZYDH
/* print '*******' */
print '***以下为院校代号:'+@YXDH+',专业代号:'+@ZYDH+'的录取确认情况***'
--取出排序在计划差额数内且志愿号为最小优先志愿号的考生,录取确认
update view_zyk_jhk_zxyxzyh set zyzt='1'
from #temp_zyk
where #temp_zyk.zy_sort <=@JHCGS
and view_zyk_jhk_zxyxzyh.zxyxzyh=#temp_zyk.zyh
and view_zyk_jhk_zxyxzyh.yxdh=@YXDH
and view_zyk_jhk_zxyxzyh.ZYDH=@ZYDH
and view_zyk_jhk_zxyxzyh.ksh=#temp_zyk.KSH
/*
select *,ROW_NUMBER()over (order by yxdh,zydh,tdcj desc) as zy_sort
into #temp_zyk
from view_zyk_jhk_zxyxzyh
where yxdh=@YXDH
and zydh=@ZYDH
select *
from #temp_zyk
where
----在临时表中,对排序在专业差额数内的进行录取
update t_zyk_new2 set zyzt='1'
from #temp_zyk
where #temp_zyk.zy_sort <=@JHCGS
and #temp_zyk.ksh=t_zyk_new2.ksh
and t_zyk_new2.YXDH=@YXDH
and t_zyk_new2.ZYDH=@ZYDH
*/
fetch @MyTestCursor into @YXDH,@ZYDH,@JHCGS
end
close @MyTestCursor
deallocate @MyTestCursor
END
GO
其中有几个不懂的点:
1:游标MyTestCursor,取一次执行下面的语句一次。那么下面的临时表#temp_zyk
不是每次都被删除了么?前面执行一次,这个表存在不就删除了么?
2:view_zyk_jhk_zxyxzyh这个视图中,我只有这个几个表t_zyk_all,t_zyk_new,t_jhk,t_zxyxzyh
,他是基于这几个表建立的视图么?是那几个表建的视图?
3:能不能告诉我整个程序的流程!
4:能搞清楚一定加分哈。谢谢