Last active
May 21, 2021 20:29
-
-
Save gxclarke/5d039c0ad0355324fba0ea4b9517a20f to your computer and use it in GitHub Desktop.
Ed-Fi ResourceClaims->Resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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