B
Brian T
I am trying to create a query that will determine the elapsed time from a
table. The table may have up to 4 timeframes.
table. The table may have up to 4 timeframes.
I am trying to create a query that will determine the elapsed time from a
table. The table may have up to 4 timeframes.
Here's the table set-up
Member Location1 Start1 End1 Location2 Start2
End2
Blow, Joe VT 2/17/1987 6/22/2001 NY
6/22/01
Doe, Jane DE 3/14/1990 3/14/2000 VT
5/15/01 4/10/08
I want to find the length of time for each location for each member.
John W. Vinson said:Here's the table set-up
Member Location1 Start1 End1 Location2 Start2
End2
Blow, Joe VT 2/17/1987 6/22/2001 NY
6/22/01
Doe, Jane DE 3/14/1990 3/14/2000 VT
5/15/01 4/10/08
I want to find the length of time for each location for each member.
Your table setup IS WRONG. You have repeating groups. I suspect you have - or,
worse, will sometime need - a Loction3, Location4 and so on!
If you have a one (member) to many (postings? not sure what the
location/start/end combination represents) then you should have two tables in
a one to many relationship.
As it is, you will need a Query based on another Query: first a UNION query to
normalize your "spreadsheet" format data:
SELECT [Member], Location1, DateDiff("d", [Start1], [End1]) AS Duration
FROM tablename
WHERE Location1 IS NOT NULL
UNION ALL
SELECT [Member], Location2, DateDiff("d", [Start2], [End2])
FROM tablename
WHERE Location2 IS NOT NULL;
Save this query and then base a Totals query on it, grouping by Member and
Location and summing Duration.
I understand having two separate tables, but how do I create the one to many
relationship?
John W. Vinson said:I understand having two separate tables, but how do I create the one to many
relationship?
Let's say you have two tables named Members and Postings (again, you have not
explained what the data means so I have no idea what a Location and date range
mean). You could then have three tables:
Members
MemberID <Autonumber, Primary Key>
LastName
FirstName
<other biographical info>
Postings
PostingID <Autonumber, Primary Key>
MemberID <Long Integer, link to Members>
Location <text, link to Locations>
StartDate <Date/Time>
EndDate <Date/Time>
Locations
Location <text, primary key>
The Locations table could be used as the rowsource of a combo box to save
typing and allow locations to be selected from a list. You could then have a
Form based on Members, with a continuous Subform based on Postings; use
MemberID as the master/child link field, and have the subform consist only of
a combo box to select the location and two textboxes for the dates. You could
add a third textbox to the subform with a control source
=DateDiff("d", [StartDate], [EndDate])
to dynamically calculate the time at that location, if it's useful to see that
info on the form.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.