CREATE PROCEDURE changezt( mess char(10) output)
begin
declare zt varchar(1);
declare ddbh varchar(14);
declare yingf float;
declare shif float;
declare tag int;
declare ztai varchar(3);
set tag=0;
declare zt_cursor cursor for select CGDD_BH,CGDD_ZT,CGDD_YFK,CGDD_SFK from cgdd_table
open zt_cursor;
fetch zt_cursor into ddbh,zt,yingf,shif;
while (fetch_status=0)
begin
select max(CGDD_BH),max(CGDD_YFK),max(CGDD_SFK),max(CGDD_ZT) into ddbh,yingf,shif,ztai from cgdd_table;
set zt=substring(ztai,3,1);
if(shif<0)
begin
set tag=1;
set mess='应付款不能为负数!';
end
else if(yingf
select mess='实付款应小于或等于应付款!';
set tag=1;
end
else
fetch zt_cursor into ddbh,zt,yingf,shif;
end;
close zt_cursor
if tag=0
begin
open zt_cursor
fetch next from zt_cursor into ddbh,zt,yingf,shif;
while (fetch_status=0)
select max(CGDD_BH),max(CGDD_YFK),max(CGDD_SFK),max(CGDD_ZT) into ddbh,yingf,shif,ztai from cgdd_table;
begin
if (yingf=0) set zt=0;
if (yingf>shif) set zt=1;
if (yingf=shif) set zt=2;
set ztai=substring(ztai,1,2)+zt;
start transaction;
update cgdd_table set CGDD_ZT=ztai where cgdd_table=ddbh;
fetch next from zt_cursor into ddbh,zt,yingf,shif;
end;
end;
close dwl_cursor;
commit;
end