Subject | Re: [firebird-support] Help with query please |
---|---|
Author | Dimitry Sibiryakov |
Post date | 2004-08-11T12:31:37Z |
On 11 Aug 2004 at 11:17, adele_leroux wrote:
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.
>The result should be multiple records where the sum of all theI'd suggest Stored Procedure.
>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.
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.