Skip to content

Instantly share code, notes, and snippets.

@gxclarke
Last active May 21, 2021 20:29
Show Gist options
  • Select an option

  • Save gxclarke/5d039c0ad0355324fba0ea4b9517a20f to your computer and use it in GitHub Desktop.

Select an option

Save gxclarke/5d039c0ad0355324fba0ea4b9517a20f to your computer and use it in GitHub Desktop.
Ed-Fi ResourceClaims->Resources
WITH
Q AS (
SELECT ResourceClaimId, ResourceName AS ResourceClaim, ParentResourceClaimId, 0 As Lvl FROM ResourceClaims WHERE ParentResourceClaimId IS NULL
UNION ALL
SELECT ResourceClaims.ResourceClaimId, ResourceClaims.ResourceName, ResourceClaims.ParentResourceClaimId, Lvl+1
FROM ResourceClaims JOIN Q ON ResourceClaims.ParentResourceClaimId = Q.ResourceClaimId
)
SELECT Q.ResourceClaim, STUFF((SELECT ', ' + Q1.ResourceClaim FROM Q Q1 WHERE Q.ResourceClaimId = Q1.ParentResourceClaimId ORDER BY Q1.ResourceClaim FOR XML PATH('')), 1, 2, '') AS Resources
FROM Q
WHERE Q.Lvl = 0
GROUP BY Q.ResourceClaimId, Q.ResourceClaim
ORDER BY Q.ResourceClaim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment