CTE Rekursion – Sample

WITH TEMP (Pk, Parent_Pk, Title, Name, Iteration) AS
(
SELECT Pk_JobStruct, Fk_Parent, Title, Name, 0
FROM T_JobStruct
WHERE PK_JobStruct = 1 -- el cheffe
UNION ALL
SELECT sub.Pk_Jobstruct, sub.Fk_Parent, sub.Title, sub.Name, (t.Iteration + 1)
FROM T_JobStruct AS sub, temp AS t
WHERE t.Pk = sub.Fk_Parent
)
SELECT * FROM Temp

Tags: CTE, Rekursion, SQL
This entry was posted on Montag, November 2nd, 2009 at 17:03 and is filed under SQL Server.
You can follow any responses to this entry through the RSS 2.0 feed.
Responses are currently closed, but you can trackback from your own site.