Subject | RE: [firebird-support] recursive procedure |
---|---|
Author | Leyne, Sean |
Post date | 2005-07-18T23:50:20Z |
Mitch,
CREATE PROCEDURE SP_CAT_PARENT (
In_ID INTEGER)
RETURNS (
Out_ID INTEGER,
DESCRIPTION VARCHAR(50),
PARENT_ID INTEGER)
AS
BEGIN
SELECT
C.ID,
C.DESCRIPTION,
C.PARENT_ID
FROM
CATEGORY C
WHERE
C.ID = :In_ID
INTO
:Out_ID,
:DESCRIPTION,
:PARENT_ID;
--return the row we found
SUSPEND;
if (:PARENT_ID IS NOT NULL) then
-- WE FOUND at least one row, AND it has a parent
FOR
SELECT
O_ID,
DESCRIPTION,
PARENT_ID
FROM
SP_CAT_PARENT(:PARENT_ID)
INTO
:Out_Id,
:DESCRIPTION,
:PARENT_ID;
DO
Suspend;
END
END
Sean
> This returns only the row I passes in, whats wrong with it?Try this:
CREATE PROCEDURE SP_CAT_PARENT (
In_ID INTEGER)
RETURNS (
Out_ID INTEGER,
DESCRIPTION VARCHAR(50),
PARENT_ID INTEGER)
AS
BEGIN
SELECT
C.ID,
C.DESCRIPTION,
C.PARENT_ID
FROM
CATEGORY C
WHERE
C.ID = :In_ID
INTO
:Out_ID,
:DESCRIPTION,
:PARENT_ID;
--return the row we found
SUSPEND;
if (:PARENT_ID IS NOT NULL) then
-- WE FOUND at least one row, AND it has a parent
FOR
SELECT
O_ID,
DESCRIPTION,
PARENT_ID
FROM
SP_CAT_PARENT(:PARENT_ID)
INTO
:Out_Id,
:DESCRIPTION,
:PARENT_ID;
DO
Suspend;
END
END
Sean