Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Difficulty writing SQL Statement
Message
 
 
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:
01371926
Views:
19
>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

I think you INNER JOINS with Rule table from the Users Table and UNION, e.g.
select * from Users INNER JOIN Rule on rule.cuserid = users.cid where Users.cID = ?vp_
UNION 
select * from Users INNER JOIN Rule on rule.cgroupid = users.cgroupid where Users.cID = ?vp_...
This is just the idea.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform