Question

For reasons I cannot understand, the people who supply my tables do not have any form of single field unique identification for the 20k+ entries in their tables.

I have two fields, BuildingCode and RoomCode, which together make up a unique room. For example:

BuildingCode    RoomCode    OtherInfo
001             100A        This is room 100 A in building 1
001             101         Different room in the same building
002             100A        This is still unique, even though two 100As exist

I know I can tell access to index both of those fields under one "MainIndex" and ensure no duplicates. What I don't know how to do is allow another table to reference one of these rooms as its parent (one to many relationship).

In my Computers table, I wish to reference one specific room. That is to say, I wish to ensure that the RoomRef is a reference to one unique room. How might I do that?

ComputerSN     RoomRef
ABC123         001-100A
ABC124         002-100A

I cannot change the layout of the given Room tables due to their way of implementing data updates (in the rooms tables).

Any help is obviously appreciated!

Était-ce utile?

La solution

Room ref should consist of two fields to match the data. It is then simple enough to join in a query. For example

 SELECT DataTable.BuildingCode, DataTable.RoomCode, Count(DataTable.RoomCode)
 FROM DataTable
 INNER JOIN LookUpTable
 ON DataTable.BuildingCode = LookUpTable.BuildingCode
 AND DataTable.RoomCode= LookUpTable.RoomCode
 GROUP BY DataTable.BuildingCode, DataTable.RoomCode

Or there abouts.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top