Subject SP question
Author s.beames@mailbox.gu.edu.au
I've finally gotten a selectable SP syntax that works for my report,
but it looks rather wordy to me! For my own edification, could
someone more experienced please advise if there a neater way of doing
this? I wanted one line per account showing the total charge for some
period.

SET TERM !! ;
CREATE PROCEDURE FBS_REPORT_PROC (startDate DATE, endDate DATE)
RETURNS (accnt SMALLINT, totalCharge DECIMAL(9,3))
AS
BEGIN
/* find distinct accounts with completed jobs within desired
timeframe */
for select ACCNT_ID from JOBS
where (COMPLETED between :startDate and :endDate)
group by ACCNT_ID
into :accnt
do
begin /* totalise the charges for this account & period */
select SUM(CHARGE) from JOBS
where (ACCNT_ID = :accnt and COMPLETED between :startDate
and :endDate)
into :totalCharge;
suspend;
end
END !!
SET TERM ; !!

Thanks,
Steve