Hello!
I'm seeking advice on a rather complex type of query I need to build
in an Access ADP (SQL-Server 7). There are four tables:
tblPeople
ID(PK) PRENAME
---------------
1 Thomas
2 Frank
3 Chris
tblInventoryClasses
ID(PK) INVENTORYCLASS
----------------------
1 Car
2 Phone
tblInventoryItems
ID(PK) relInvClass(FK) ITEM
-----------------------------------
1 1 Dodge Viper
2 1 Chrysler
3 2 Nokia
4 2 Samsung
tblPeopleInventory
ID(PK) relPeople(FK) relInvItem(FK)
--------------------------------------
1 1 2
2 1 3
3 2 1
4 2 3
5 3 4
In this example the last table tells me that
Thomas owns a Chrysler (class Car) and a Nokia (class Phone).
Can someone tell me how to write a query or a stored procedure which
produces a resultset like this:
qryOwners
People Car Phone
-----------------------------
Thomas Chrysler Nokia
Frank Dodge Viper Nokia
Chris [NULL] Samsung
The main idea is that I need to be able to iterate such a collection.
It is guranteed that one "People" only owns one or zero "Car" and one
or zero "Phone".
I guess that it might be impossible to design a stored procedure with
such a variable amount of columns (in this case, each item from
tblInventoryClasses would mean another column).
Ary there any possibilities in accomplishing this without creating
temporary tables?
Any help would be really appreciated ;-)
Greetings,
Christoph Bisping