Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alaawahbah/048612b3331eb5bf901cd7942d838b8d to your computer and use it in GitHub Desktop.
Save alaawahbah/048612b3331eb5bf901cd7942d838b8d to your computer and use it in GitHub Desktop.
SELECT p.Name as PermissionName, (STUFF( (select ',' + r.Name from Roles r where r.id in (select RoleId from RolePermissions rp where rp.RoleId =r.Id and rp.PermissionId = p.Id )
FOR XML PATH('')),
1, 1, '')) AS RoleName
FROM Permissions p
-------------------------------------------------
DECLARE @CodeNameString varchar(100)
SELECT
@CodeNameString = STUFF( (select ',' + r.Name from Roles r where r.id in (select RoleId from RolePermissions rp where rp.RoleId =r.Id and rp.PermissionId = p.Id )
FOR XML PATH('')),
1, 1, '')
print @CodeNameString
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment