hello i have a problem in a procedure...
am trying to recalculate all invoices in the database
invoices have header and details
here's the code that i am using
am getting a cursor not open error...
what's the problem?
am trying to recalculate all invoices in the database
invoices have header and details
here's the code that i am using
Code:
create procedure "dba".RecalculateAllInvoices()
begin
declare err_notfound exception for sqlstate value '02000';
declare tn integer;
declare Results dynamic scroll cursor for select transnum from supinvoice_header;
open Results;
ResultsLoop: loop
fetch next Results into tn;
if sqlstate=err_notfound then
leave Resultsloop
end if
;
Call RecalculateInvoice(tn)
end loop ResultsLoop;
close Results;
commit transaction
end
Code:
alter procedure "dba".RecalculateInvoice(@transnum integer)
as
begin
declare @tax1ex double,
@tax1 double,
@amount double,
@vatrate double,
@invid integer,
@rd double
select @invid=id,@rd=realdiscount from supinvoice_header where transnum=@transnum
select @vatrate=doublevalue from settings where id='VATRATE'
select @tax1ex=sum(qty*costpsu*(100-discount)*(100-@rd)/10000),@tax1=sum(qty*costpsu*(100-discount)*istax1*@vatrate*(100-@rd)/10000),@amount=sum(qty*costpsu*(100-discount)*(1+(istax1*@vatrate))*(100-@rd)/10000)
from supinvoice_detail where supinvheaderid=@invid
update supinvoice_header set amount=@amount,tax1ex=@tax1ex,tax1=@tax1 where id=@invid
commit transaction
end
am getting a cursor not open error...
what's the problem?