Subject RE: [firebird-support] Re: Tree Sql query
Author Steffen Heil
Hi

> I second that request for an example of a SP for handling Trees.
Generally, I've been still doing this locally in my program (and it may not
be a big issue since I'm running everything locally), but I'd like to learn.

I have the following in use:

id parent_id
1001 null
1002 1001
1003 1001
1004 1002
1005 1002
1006 1003
1007 1003

CREATE PROCEDURE REC_LIST (
SCAN_ID INTEGER)
RETURNS (
PARENT_ID INTEGER,
FOUND_ID INTEGER)
AS
begin
for select id, parent_id
from pages_node
where parent_id = :scan_id
into found_id, parent_id
do begin
suspend;
for select parent_id, found_id
from rec_list( :found_id )
into parent_id, found_id
do
suspend;
end
end


Regards,
Steffen