Subject Re: [firebird-support] Help with query please
Author Dimitry Sibiryakov
On 11 Aug 2004 at 11:17, adele_leroux wrote:

>The result should be multiple records where the sum of all the
>records returned does not exceed 500. If this is not possible by using
>a select query, I would appreciate any input on how to accomplish this
>without retrieving all the records from the database.

I'd suggest Stored Procedure.

CREATE PROCEDURE Get500 (ID INTEGER, MyLength INTEGER) AS
DECLARE VARIABLE Total;
BEGIN
Total = 0;
FOR SELECT UniqueID, MyLength FROM MyTable ORDER BY MyLength
INTO :ID, :MyLength DO
BEGIN
Total = Total+MyLength;
IF(Total>500) THEN EXIT;
SUSPEND;
END;
END^

SY, Dimitry Sibiryakov.