Subject "for select' with 'ORDER" clause in stored procedure
Author Christian Waldmann
Hello

Environment: Windows XP SP3, Firebird 2.1.3 SuperServer, IBExpert,
Development Server, only 1 connection (SYSDBA in IBExpert)

I use the following selct in a SQL-Editor and the result is ordered by
o.LOGTIMESTAMP

select cast( o.LOGTIMESTAMP as time) as logtime, cast(
t.logtimestamp as time) - cast( o.logtimestamp as time ),
o.food - t.food as foodDelta,
o.kind
from procGetAnimalVisitKindSP1( :animal, :visitDate, 'O',
'V' ) o /* V)isit, O)pen */
inner join procGetAnimalVisitKindSP1( :animal, :visitDate,
'C', 'L') t /* L)eaving, C)lose */
on (o.visitId = t.visitId)
where o.UNIQUEID < t.UNIQUEID
order by o.LOGTIMESTAMP /*
<======================== */


I use the same select in a for loop in a stored procedure. The procedure
compiles and runs, but the order clause has no effect!
(The result set is returned in the order of o.visitid)


stored Procedure ....

for select cast( o.logtimestamp as time ) as logtime,
cast( t.logtimestamp as time) - cast( o.logtimestamp as time
),
o.food - t.food as foodDelta,
o.kind
from procGetAnimalVisitKindSP1( :animal, :visitDate, 'O', 'V' )
o /* V)isit, O)pen */
inner join procGetAnimalVisitKindSP1( :animal, :visitDate,
'C', 'L') t /* L)eaving, C)lose */
on (o.visitId = t.visitId)
where o.UNIQUEID < t.UNIQUEID
order by o.LOGTIMESTAMP /*
<======================== */
into :visitTime, :visitDuration, :visitDelta, var_arrivalKind
do begin
/* some code */
suspend;
end


Is the order clause useless by design in a "for ... select ORDER into
... begin SUSPEND; end" construct?
If so, I would expect an error or at least a warning!
If not, what am I doing wrong?

Christian Waldmann