Subject | [ib-support] Re: SP syntax problems |
---|---|
Author | Alan J Davies |
Post date | 2002-11-28T18:13:51Z |
Alexander V.Nevsky responded to my request for assistance on problems with
an sp
Thanks for pointing me in the right direction - I have rewritten the sp as
follows and it works.
The Select routines are ended with ";" They were originally - For Select
.... but that does not work
This type of routine should work for anyone needing to update one table
based on parameters from the same table and one (or more) other table -
/* Update Postings from Ledger -
Set all Postings.Total to zero where the Ledger.balance is zero,
the Postings.Acno is the same as the Ledger.Acno,
and the sum of Debit.postings = sum of credit.postings.
*/
CREATE PROCEDURE AC_POSTINGS_AUTOALLOCATE
(
LEDGERTYPE CHAR(10)
)
AS
BEGIN EXIT; END ^
ALTER PROCEDURE AC_POSTINGS_AUTOALLOCATE
(
LEDGERTYPE CHAR(10)
)
AS
Declare Variable LEDGERACNO CHAR(5);
Declare Variable LEDGERBALANCE NUMERIC(9, 2);
Declare Variable DR_TOTAL NUMERIC(9, 2);
Declare Variable CR_TOTAL NUMERIC(9, 2);
begin
if (Ledgertype='Sales ') then
begin
For Select Acno, Balance
From Sledger
Where Balance=0
into LEDGERACNO,LEDGERBALANCE
do
begin
Select Sum(Total)
From Sposting
Where Acno=:LedgerAcno
And Dr_Cr='D'
into DR_TOTAL;
Select Sum(Total)
From Sposting
Where Acno=:LedgerAcno
And Dr_Cr='C'
into CR_TOTAL;
if (absflt(DR_TOTAL)=absflt(CR_TOTAL)) then
begin
Update Sposting
Set Paid='Y',Total=0
Where Acno=:LEDGERACNO
And :LEDGERBALANCE=0;
end
end
Alan J Davies
email: alan@...
an sp
Thanks for pointing me in the right direction - I have rewritten the sp as
follows and it works.
The Select routines are ended with ";" They were originally - For Select
.... but that does not work
This type of routine should work for anyone needing to update one table
based on parameters from the same table and one (or more) other table -
/* Update Postings from Ledger -
Set all Postings.Total to zero where the Ledger.balance is zero,
the Postings.Acno is the same as the Ledger.Acno,
and the sum of Debit.postings = sum of credit.postings.
*/
CREATE PROCEDURE AC_POSTINGS_AUTOALLOCATE
(
LEDGERTYPE CHAR(10)
)
AS
BEGIN EXIT; END ^
ALTER PROCEDURE AC_POSTINGS_AUTOALLOCATE
(
LEDGERTYPE CHAR(10)
)
AS
Declare Variable LEDGERACNO CHAR(5);
Declare Variable LEDGERBALANCE NUMERIC(9, 2);
Declare Variable DR_TOTAL NUMERIC(9, 2);
Declare Variable CR_TOTAL NUMERIC(9, 2);
begin
if (Ledgertype='Sales ') then
begin
For Select Acno, Balance
From Sledger
Where Balance=0
into LEDGERACNO,LEDGERBALANCE
do
begin
Select Sum(Total)
From Sposting
Where Acno=:LedgerAcno
And Dr_Cr='D'
into DR_TOTAL;
Select Sum(Total)
From Sposting
Where Acno=:LedgerAcno
And Dr_Cr='C'
into CR_TOTAL;
if (absflt(DR_TOTAL)=absflt(CR_TOTAL)) then
begin
Update Sposting
Set Paid='Y',Total=0
Where Acno=:LEDGERACNO
And :LEDGERBALANCE=0;
end
end
Alan J Davies
email: alan@...