Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Not Sure How To Code This Query
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Autre
Divers
Thread ID:
01397296
Message ID:
01397302
Vues:
42
>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.*, R.*, 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'

Actually, I meant to add Rights as RG - anyway, this would be simple enough.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform