Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to create this table?
Message
 
To
30/07/2003 13:18:45
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00815002
Message ID:
00816159
Views:
22
*-- The key is only use view when you need to do inserts/updates/deletes.
*-- Try this sample code and see if it helps!
LOCAL lcEscape
lcEscape=SET("ESCAPE")

SET ESCAPE OFF
*-- Your problem is you are using views. This type of information is best
*-- maintained in a tight table using select statements. If you need to update
*-- or view the records, find out what you need to insert, view, delete BEFORE you create the view,
*-- then use the view only to retrieve the specific record.

*-- A simple table will solve this problem
CLOSE ALL
CREATE cursor people (lastname c(15), FIRSTNAME C(10), TEAM INT,LEADER L)

INSERT INTO people (lastname,firstname,team, leader) values ("ALPHA","ADAM",1,.T.)
INSERT INTO people (lastname,firstname,team, leader) values ("BETA","BARRY",2,.T.)
INSERT INTO people (lastname,firstname,team, leader) values ("CHARLIE","CHRIS",3,.T.)
INSERT INTO people (lastname,firstname,team, leader) values ("DELTA","DON",4,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("ECHO","EDWARD",1,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("FOXTROT","FANNY",2,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("GOLF","GANNY",3,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("HARRIET","HARRY",1,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("INDIVIDUAL","INDY",2,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("JONES","JULIET",3,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("KON","KARRIE",1,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("LUCENT","RIPOFF",2,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("MONEY","MARY",3,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("NONE","NATHAN",1,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("OH","OKAY",2,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("PERRY","PUNT",3,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("QUARANTINE","QUE",0,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("RETOR","ROBERT",0,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("STILL","SAM",0,.F.)
INSERT INTO people (lastname,firstname,team, leader) values ("THOMAS","TILLING",0,.F.)

*-Your first critieria:
*-a. There can only be one team leader per team
*-You need a teams table. But lets use this one
*- b. A person can only lead one team at a time
SELECT * FROM people where leader = .T. && leaders
BROW NOWAIT
WAIT WINDOW "Team Leaders"

*- The fact that team and leader only allow one value satifies this criteria
*- c. A person can only be amember of one team at any given time
SELECT * FROM people where leader = .F. ORDER BY team, lastname && members
BROW NOWAIT
WAIT WINDOW "Members of teams"
*- We only have one integer value for team, so can we cannot be a member of more than one

*- d. A person can not be a member of one team and a leader of anotehr
SELECT count(*) AS ncnt, TEAM FROM people group by team && members in each group
BROW NOWAIT
WAIT WINDOW "All Members Assuming Leader is Counted " NOWAIT
*-- You could exclude team leader with leader=.F.F

*- e. A team can have unlimited members. No problem

*-- Potential team leader but not a member of an exiting team
SELECT * FROM people WHERE !leader AND team=0 && select * from people where leader = .f.
&& select * from people where leader = 0 && if using bit on SQL
BROW NOWAIT
WAIT WINDOW "Potential Team Leaders who are not" + chr(13) + "a team leader"
*-- I hope this helps!

SET ESCAPE &lcEscape
Previous
Reply
Map
View

Click here to load this message in the networking platform