Subject Re: Re: Re: [firebird-support] selecting missing numbers from sequential data
Author Pavel Menshchikov
Hello,

Sorry, obviously IF condition in my previous post was wrong: I forgot
to include NOT before EXISTS.
PM> -----
PM> CREATE PROCEDURE GET_missing_tickets
PM> RETURNS (Missing_number integer)
PM> AS
PM> declare variable last_ticket integer;
PM> declare variable ticket integer;
PM> begin
PM> select min(ticket_code)
PM> from deliveries
PM> into :ticket;
PM> select max(ticket_code)
PM> from deliveries
PM> into :last_ticket;

PM> /* omit the first and the last */
PM> ticket = ticket + 1;
PM> last_ticket = last_ticket - 1;

PM> while (ticket <= last_ticket) do
PM> begin
PM> if (NOT exists(select 1 from deliveries
^^^
PM> where ticket_code = :ticket)) then
PM> begin
PM> Missing_number = ticket;
PM> suspend;
PM> end
PM> ticket = ticket + 1;
PM> end
PM> end
PM> -----


--
Best regards,
Pavel Menshchikov
http://www.ls-software.com