Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difficulty writing SQL Statement
Message
From
07/01/2009 21:04:25
 
 
To
07/01/2009 20:05:55
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01371924
Message ID:
01371935
Views:
15
>Hello all, I feel stupid. I have been battling a SQL statement for about three 3 hours. Maybe these 12 hour work days are starting to get to me! I am trying to find all 'rule' related security records for a user, and a user in a group.
>The rule table has a cuserid, and a cgroupid, to designate if the rule appies to a user or a group. A user can have both group rules and individual rules. The cgroupid is stored in the user table, since the user can only be in one group.
>I cannot create SQL to get all rules correctly. I can manage the rules with the cuserid filled in (the individual rules) but I can't manage to make the SQL grab the rules when a user has both individual and group rules. Part of the complication comes from the fact that my foreign keys are never blank, they contain a ZZZZZZ ID to a default record in each table to maintain referential integrity. So, a group rule will have ZZZZZZ as the user id, but a real group cid, and an individual rule will have a real user id and a ZZZZZZ group id.
>My SQL is as follows:
>
>select users.clogin,rule.*;
>	from ;
>	rule,users ;
>	where rule.cuserid = users.cid ;
>	and (rule.cuserid = ?vp_cuserid ;
>	OR (users.cid = ?vp_cuserid AND rule.cgroupid = users.cgroupid));
>	order by rule.ctype desc
>
>
>I am attempting to write this for a view, hence the view parameters. When a user visits a grid, I want them to see all their rules, both individual and inherited from the group. I hope I have explained this adequately. I feel I am missing something very elemental here. Any help is appreciated.
>TIA
>Amanda
Does this work???
SELECT users.clogin,rule.* ;
  FROM users ;
    JOIN rule ON rule.cuserid = users.cid OR rule.cgroupid = users.cgroupid;
  WHERE users.cid = vp_cuserid
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform