/*
功能:将已启用活动的期间升级到TBHDQJ
版权:王茂健
时间:20110922
*/
declare v_slnm varchar2(36);
cursor myCursor is select tbfasl_slnm from tbfasl where tbfasl_stat='1';
Begin
open myCursor;
fetch myCursor into v_slnm;
while myCursor%found
loop
declare v_sql varchar2(1000);
v_count int:=0;
begin
select count(1) into v_count from tbhdqj where tbhdqj_slnm=''||v_slnm||'';
if(v_count<=0)
then
v_sql :='insert into tbhdqj select tbslqj_slnm,tbslqj_xh,tbslqj_xdqj,tbslqj_zqnm,
(case when tbbzqj_bzlx=''B'' and left(TBBZQJ_QJ,1)<>''-'' then ''0'' when tbbzqj_bzlx=''Q'' then ''1'' else ''1'' end)
from tbslqj2,tbbzqj where tbslqj_slnm='''||v_slnm||'''
and tbbzqj_znm=tbslqj_znm and tbbzqj_zq=tbslqj_zqnm and tbbzqj_qj=tbslqj_xdqj';
execute immediate v_sql;
end if;
fetch myCursor into v_slnm;
end;
end loop;
close myCursor;
End;