July 7, 2008 at 5:53 am
Hi,
I am currently building a website menu system which is stored in SQL Server and which will be permission driven.
In the frontend I have 3 enumerated roles.
Reader = 1
Admin = 2
Developer = 4
A user can be any combination of the above. Next to each menu item I store the required permission level. So a menu item with a permission level of 7 should be able to be seen by roles: Reader, Admin and Developer, whereas a menu permission of 6 should only be seen by anyone assigned to roles: Admin or Developer.
I have tried the following syntax but this does not work.
SELECT MenuItem, URL
FROMMenu
WHERE ((@permission & Permission) = @permission)
Using this approach if @permission = 3 (Reader and Admin) it doesn't pick up where Permission = 6 (which it should because Admin is in 6).
Hope this makes sense. Any help would be gratefully received.
Thanks
Corun
July 7, 2008 at 6:28 am
Since you are not requiring that all permission bits should be present when comparing, but only one permission bit is set, you could use:
SELECT MenuItem, URL
FROM Menu
WHERE ((@permission & Permission) > 0)
Regards,
Andras
July 7, 2008 at 6:32 am
Thanks that's exactly what I was looking for 🙂
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply