Jump to content
Sign in to follow this  
Henry Olive

FB-3,09 Recursive CTE

Recommended Posts

I wish everyone a healthy day

I'm testing to use Recursive CTE instead of my Recursive S.Proc.

 

WITH RECURSIVE CTE AS (SELECT B.ITEMCODE, B.SUBITEMCODE, IT.ITEMTYPE, B.QTY,
V.CUSTNO, V.PRICE, IT.STOCK
FROM BOM B 
JOIN ITEMS IT ON IT.ITEMCODE=B.SUBITEMCODE
JOIN VENDOR V ON V.ITEMCODE=B.SUBITEMCODE )

SELECT ITEMCODE, SUBITEMCODE, ITEMTYPE, QTY,  CUSTNO, PRICE, STOCK
FROM CTE
WHERE ITEMCODE='ABC'

 

Above Query works but it doesnt explode the BOM, just shows BOM table's datas.

Thank You

 

 

 

Share this post


Link to post
Guest

Your CTE is in fact not recursive as it doesn't reference itself or use UNION ALL.

Generalized syntax for a recursive CTE looks like this:

WITH RECURSIVE <cte_alias> AS (
SELECT <parent data> -- root nodes data
UNION ALL
SELECT <child data> -- childrens data
JOIN <cte_alias> ON <parent_link>
) -- DO // for the Delphians
SELECT * FROM <cte_alias>

Source:
https://www.firebirdsql.org/file/community/ppts/fbcon11/FBTrees2011.pdf

Share this post


Link to post
Guest

Without UNION ALL referencing itself, it's just a non-recursive CTE.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×