Skip to content

Instantly share code, notes, and snippets.

@justintoth
Created March 12, 2012 18:54
Show Gist options
  • Save justintoth/2023952 to your computer and use it in GitHub Desktop.
Save justintoth/2023952 to your computer and use it in GitHub Desktop.
RBA_Get_PermissionsByRole
CREATE PROCEDURE [dbo].[RBA_Get_PermissionsByRole]
@RoleId INT
AS
BEGIN
SET NOCOUNT ON;
SELECT p.id as PermissionId, p.Name, p.[key] as [Key], parent.[key] as ParentKey, p.MaxBits, p.MinBits, rp.PermissionBit, dp.[key] as [Dependency]
FROM role_permission rp WITH (NOLOCK)
JOIN permission p WITH (NOLOCK) ON rp.permissionid = p.id
LEFT JOIN permission parent WITH (NOLOCK) ON p.parentid = parent.id
LEFT JOIN permissiondependency dep WITH (NOLOCK) ON p.id = dep.permissionid
LEFT JOIN permission dp WITH (NOLOCK) ON dep.dependentpermissionid = dp.id
WHERE rp.Roleid = @RoleId
AND p.id IN
(
SELECT permissionid
FROM company_permission cp WITH (NOLOCK)
JOIN role r WITH (NOLOCK) ON cp.companyid = r.companyid
WHERE r.id = @roleid
)
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment