Tim said:
@newsread1.news.pas.earthlink.net:
People (
*PersonID
FName
LName
Address...)
Employees (
*PersonID FK references People
DepartmentCode
StartYear
IncrementDate...)
SeniorManagers (
*PersonID FK references Employees
NumberOfForeignHomes
WifesBirthday
ExecToiletPassNumber...)
Anyone for a suggestion for a sub-sub-sub-typing solution?
All the best
Tim F
Yes, you can do that (unlimited number of levels) via a self-join, in
which you (for example) join the [Employees] Table to a copy of itself,
which you might call [Employees_Supervisors]. (It's a copy of a
reference to the Table; you don't actually copy any real records.)
For example, let's add a few records to your Tables. We're going to set
up 2 levels of supervisors. Incidentally, I assume you have other
references from other Tables to the records in [People], else there
would be little need to split out those fields -- they could simply be
stored in [Employees].
[People] Table Datasheet View:
PeopleID FName LName Address
----------- ----- ------ ---------------------
-1739752905 Judy Grunt 118 Drury Lane
-1724904251 Punch Peon 3352 Crazy Quilt Ave.
-506694726 Big Kahuna The Palace
1711311566 Boss Honcho The Ritz
Now we add, in [Employees], the records peculiar to an employee, such as
a reference to a supervisor:
[Employees] Table Datasheet View:
EmployeeID PeopleID StartYear Increment Employees_SupvID
Date
---------- ----------- --------- --------- ----------------
472638892 1711311566 11/7/2001 11/7/2003 761885619
761885619 -506694726 1/1/1985 1/1/1986 0
1417722657 -1724904251 11/7/2005 472638892
1930422077 -1739752905 3/3/2004 3/3/2005 472638892
Some people here on the m.p.a.t. NG dislike using lookup fields, so the
above display shows only the key values. If you avoid using lookups,
please ignore the following display. However, since I think lookup
fields are almost essential when one has to deal with key values, here's
how I would show the same Datasheet View, using lookup values:
[Employees] Table Datasheet View, with lookup fields:
EmployeeID PeopleID StartYear Increment Employees_SupvID
Date
----------- ----------- --------- --------- ----------------
472638892 Boss Honcho 11/7/2001 11/7/2003 Big Kahuna
761885619 Big Kahuna 1/1/1985 1/1/1986 0
1417722657 Punch Peon 11/7/2005 Boss Honcho
1930422077 Judy Grunt 3/3/2004 3/3/2005 Boss Honcho
Having populated our two Tables, we can now display a list of everyone's
supervisor (except the top dog), via this Query:
[Q_Supervisors] SQL:
SELECT [People]![FName] & " " & [People]![LName]
AS EmpName,
People.Address AS EmpAddr,
"Mr/Ms " & People_Supv!LName AS SupvName
FROM ((Employees INNER JOIN Employees AS Employees_Supv
ON Employees.Employees_SupvID
= Employees_Supv.EmployeeID)
INNER JOIN People AS People_Supv
ON Employees_Supv.PeopleID = People_Supv.PeopleID)
INNER JOIN People
ON Employees.PeopleID = People.PeopleID
ORDER BY People.LName, People.FName;
In Datasheet View, the results are...
[Q_Supervisors] Query Datasheet View:
EmpName EmpAddr SupvName
----------- --------------------- ------------
Judy Grunt 118 Drury Lane Mr/Ms Honcho
Boss Honcho The Ritz Mr/Ms Kahuna
Punch Peon 3352 Crazy Quilt Ave. Mr/Ms Honcho
So you have 3 levels of supervision with only 2 Tables, and you could as
easily have dozens of levels. No further changes to the Table design
(nor to the Query) would be needed to accommodate those.
Of course, if new types of fields are needed for the executive suite,
you'd need that [SeniorManagers] Table, and I assume a separate field to
link to it.
-- Vincent Johns <
[email protected]>
Please feel free to quote anything I say here.