Article View: borland.public.interbase.sql
Article #11350Re: FOR SELECT LOOP
From: Arno Brinkman
Date: Sat, 23 Nov 2002 17:56
Date: Sat, 23 Nov 2002 17:56
61 lines
2414 bytes
2414 bytes
Hi,
> Somewhere in this newsgroup, a solution for merging two query's resulting
in
> one table (where the result of the queries is in different column of the
> table) was to use a FOR SELECT LOOP in a procedure.
>
> I tried this because it looked like it was the ideal solution for a
problem
> that I had.
>
<snip>
It seems that you forgot that every "sub-query" should be in the BEGIN - END
block.
Try :
CREATE PROCEDURE TESTFORLOOP
RETURNS (
TOTAL3 NUMERIC(11,2),
TOTAL2 NUMERIC(15,2),
TOTAL1 NUMERIC(15,2),
DAT DATE)
AS
begin
/* Procedure Text */
FOR SELECT DISTINCT Invoices.date
FROM Invoices
WHERE Invoices.month= '200209'
INTO :DAT
do
begin
/* First Total */
select SUM(InvoiceD.total)
from Invoices Join InvoiceD ON Invoices.invnum = InvoiceD.number
where Invoices.date = :DAT and InvoiceD.returnc = 1
GROUP BY Invoices.date
INTO :TOTAL1;
/* Second Total */
select SUM(InvoiceD.total)
from InvoicesJoin InvoiceD ON Invoices.invnum = InvoiceD.InvoiceD.number
where Invoices.date = :DAT and InvoiceD.returnc = 2
GROUP BY Invoices.date
INTO :TOTAL2;
/* Thirth Total */
select SUM(InvoiceD.total)
from Invoices Join InvoiceD ON Invoices.invnum =
InvoiceD.InvoiceD.number
where Invoices.date = :DAT and InvoiceD.returnc = 3
GROUP BY Invoices.date
INTO :TOTAL3;
end
end
Regards,
Arno Brinkman
Technical Details
Message-ID:
<3ddfc059@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3ddfb5ea$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 114a0e,93dd659978b88a04 X-Google-Attributes: gid114a0e,public X-Google-ArrivalTime: 2002-11-23 09:55:31 PST From: "Arno Brinkman" <bnewsgroups @ abvisie.nl> Newsgroups: borland.public.interbase.sql References: <3ddfb5ea$1@newsgroups.borland.com> Subject: Re: FOR SELECT LOOP Date: Sat, 23 Nov 2002 18:56:45 +0100 Lines: 63 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 NNTP-Posting-Host: 213.116.126.173 Message-ID: <3ddfc059@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1038073945 213.116.126.173 (23 Nov 2002 09:52:25 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-05!sn-xit-01!sn-xit-04!supernews.com!news.maxwell.syr.edu!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail