Re: TOP 100 in SQL
Posted in 1998
Topics: SQL Development & Query Writing, Stored Procedures & SPL, Jobs, Consulting & Announcements
rfurdzik@paulweiss.com wrote:
> How to display only first 100 rows from a query ??? Please help
>
> Select a, sum(b)
> group by a DESC>
Try a calling a stored procedure like this one:
create procedure proc() returning integer, integer; define a integer;
define sumb integer;
define cnt integer;
let cnt=0;
foreach select a, sum(b) into a, sumb from x group by a desc
if cnt > 100 then
return;
end if;
let cnt = cnt + 1;
return a, sumb with resume;
end foreach;
end procedure;
It is true that it doesn't perform as smooth as the "first N" clause
(where this one functions) but it has the advantage that it is way
more complicated.
Paul Aanei
-------------------------------------------------------------
Epitaph:
Here lyes Paul Valery - killed by the others.
-------------------------------------------------------------