Does RightID in UserRights table refer to the RightID in Rights table? If we join UserRights with Rights, will we get the rights for this user?
>I don't think you understand. I want back a user's rights, not all data in all tables.
>
>Rights are assigned to a role, then altered for a specific user. Those records end up in UserRights. So when the query is run, taking a UserId, it should produce a table of only those UserRight records that allow access. I'm envisioning a 3 column table - RecordId, RightKey, Access.
>
>
>
>
>
>
>>>I have Users, Roles, Rights, RoleRights, and UserRights.
>>>
>>>I want to pull the rights for a user. So it should first look at the user's Role Rights, then overwrite those rights from the UserRights table:
>>>
>>>Here's the table structures:
>>>
>>>
>>>TABLE: Users
>>>UserId RoleId FullName
>>>
>>>38 14 Some One
>>>39 15 Aother Person
>>>
>>>
>>>TABLE: Roles
>>>RoleId RoleName RoleCode
>>>
>>>31 Administrtor adm
>>>32 Shipping shp
>>>33 Receiving rcv
>>>
>>>
>>>TABLE: Rights
>>>RightId RightName RightCode Access
>>>
>>>10 Login login 1
>>>11 View Ship Items vw_shipitems 1
>>>
>>>
>>>TABLE: RoleRights
>>>RoleRightId RoleId RightId Access
>>>
>>>16 32 10 NULL
>>>17 32 11 NULL
>>>
>>>
>>>TABLE: UserRights
>>>UserRightId UserId RightId Access
>>>
>>>17 32 11 0
>>>25 33 18 0
>>>
>>>
>>>
>>>I know how to do this with temp tables, but can someone show me how to code this in a query, if it's possible?
>>
>>From UserRights to RoleRights based on RightID
>>From RoleRights to Rights and Roles
>>
>>So try
>>
>>select U.*, RL.*, RG.* from Users U INNER JOIN UserRights UR on U.UserID = UR.UserID INNER JOIN
>>RoleRights RG ON UR.RightID = RG.RightID INNER JOIN Roles R ON RG.RightID = R.RoleID where U.FullName = 'Kevin'
If it's not broken, fix it until it is.
My Blog