Subject | Re: [firebird-support] SP question BOMVIEW recursive SP call |
---|---|
Author | Alex Taylor |
Post date | 2004-01-07T13:07:19Z |
Hey!
Look at this code snippet. Maybe it will help You. It works for me. This
procedure pass back all the sub-partners of a given partner.
It is recursive of course and works fine.
CREATE PROCEDURE GET_SUB_PARTNERS(
PARENT_CODE SMALLINT)
RETURNS (
P_CODE SMALLINT,
NAME CHAR(50))
AS
DECLARE VARIABLE HAS_CHILDREN SMALLINT;
BEGIN
FOR SELECT P_CODE,NAME FROM PARTNER WHERE PARENT_CODE=:PARENT_CODE
INTO :P_CODE, :NAME DO
BEGIN
SELECT COUNT(*) FROM PARTNERS WHERE PARENT_CODE=:P_CODE INTO
:HAS_CHILDREN;
IF (HAS_CHILDREN<>0) THEN
BEGIN
SELECT P_CODE, NAME FROM GET_SUB_PARTNERS(:P_CODE) INTO
:P_CODE, :NAME;
END
SUSPEND;
END
END
Regards: Alex Taylor
Look at this code snippet. Maybe it will help You. It works for me. This
procedure pass back all the sub-partners of a given partner.
It is recursive of course and works fine.
CREATE PROCEDURE GET_SUB_PARTNERS(
PARENT_CODE SMALLINT)
RETURNS (
P_CODE SMALLINT,
NAME CHAR(50))
AS
DECLARE VARIABLE HAS_CHILDREN SMALLINT;
BEGIN
FOR SELECT P_CODE,NAME FROM PARTNER WHERE PARENT_CODE=:PARENT_CODE
INTO :P_CODE, :NAME DO
BEGIN
SELECT COUNT(*) FROM PARTNERS WHERE PARENT_CODE=:P_CODE INTO
:HAS_CHILDREN;
IF (HAS_CHILDREN<>0) THEN
BEGIN
SELECT P_CODE, NAME FROM GET_SUB_PARTNERS(:P_CODE) INTO
:P_CODE, :NAME;
END
SUSPEND;
END
END
Regards: Alex Taylor