klaushaidinger.com

Icon

Recursive queries in SqlServer

WITH MeineGruppen(Parent, Subitem) as
(
— Base query
SELECT n_parent, n_lfdgruppe
FROM ugruppe
WHERE n_parent = 10625
UNION ALL
— Recursive query
SELECT me.Parent, dm.n_lfdgruppe
FROM MeineGruppen AS me
JOIN ugruppe AS dm
ON me.Subitem = dm.n_parent
WHERE me.Parent = 10625
)
SELECT * FROM MeineGruppen ORDER BY Subitem

Category: Microsoft Sql Server

Tagged:

Comments are closed.