473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Access Date lookup query help

4
Hello everyone this is my first post so as you could guess I need some help. Here is my situation, I have 2 tables, one caled personnel and one called DET_Dates, DET_Dates is linked to Personnel on Admin_ID. The Perrsonnel table has a list of names and dates pertaining to that person, the DET_Date table contains events and dates of events that each person in the Personnel table participated in. What I need to do and have been trying to do is build a query to single out the last time VACATION took place for each indifudual and calculate how long that event was. The sample DET_Date table is below and what I think I need the query return.

I could do this by going to the table and adding some type of identifer to the type like L_VACATION but that would mean more work for me or someone else down the road when that particular VACATION was no longer the last one.

I need some help, I already have some gray hair but getting more from this.

Thanks,
Photo

Outcome I need
Admin_ID************** DET_ID***** Detachment_Name*************** Start Date ***End Date *******TYPE*****Length
12 ***********************240 *****************C************************ 23-Jan-06* ***03-Feb-06**** VACATION****10
14 *********************** 67 ***************** F************************* 01-Jan-07* ** 29-Jan-07**** VACATION****29
33 ***********************48 ***************** H************************* 01-Jan-07* ** 10-Jan-07**** VACATION*****10

Sample DET_Dates
Admin_ID************** DET_ID***** Detachment_Name*************** Start Date ***End Date *******TYPE
1 *********************** *44 ***************** A************************* 13-Feb-06* ** 15-Mar-06**** SCHOOL
12 ***********************238 **************** B************************* 01-Jul-05* ** 30-Jul-05******* VACATION
12 *********************** 240 ****************C ************************ 23-Jan-06* ** 03-Feb-06**** VACATION
12 *********************** 250 ****************D************************* 01-Mar-06* ** 05-Mar-06**** TEACH
14 *********************** 63 *****************E ************************* 23-Jan-06* ** 29-Jan-06**** VACATION
14 *********************** 67 *****************F ************************* 01-Jan-07* ** 29-Jan-07**** VACATION
33 *********************** 49 *****************G ************************* 20-Jan-06* ** 31-Jul-06**** VACATION
33 ***********************48 ******************H************************* 01-Jan-07* **10-Jan-07**** VACATION
33 ***********************46 ***************** I ************************* 20-Jan-06* ** 31-Jul-06**** SCHOOL
Mar 30 '07 #1
5 1548
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. SELECT AdminID, DET_ID, Detachment_Name, TYPE,
  2. Max(Start Date) As Start Date, Max(End Date) As End Date
  3. FROM DET_Dates
  4. WHERE TYPE = 'VACATION'
  5. GROUP BY AdminID, DET_ID, Detachment_Name, TYPE;
  6.  
Mary
Apr 1 '07 #2
Photo
4
Thanks for the help, I tried the code but I had to add some additional info to get it to do anything at all. Now I runs but list every instance of "vacation" for each person and I just need the very last one. Any suggestions?

Expand|Select|Wrap|Line Numbers
  1.  SELECT PERSONNEL.Admin_ID, DET_Dates.DET_ID, DET_Dates.Detachment_Name, DET_Dates.TYPE, Max(DET_Dates.[Start Date]) AS [Start Date], Max(DET_Dates.[End Date]) AS [End Date]
  2. FROM DET_Dates INNER JOIN PERSONNEL ON DET_Dates.Admin_ID = PERSONNEL.Admin_ID
  3. WHERE (((DET_Dates.TYPE)='vacation'))
  4. GROUP BY PERSONNEL.Admin_ID, DET_Dates.DET_ID, DET_Dates.Detachment_Name, DET_Dates.TYPE
Photo
Apr 2 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Try this without adding any other fields.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT PERSONNEL.Admin_ID, DET_Dates.TYPE,
  3. Max(DET_Dates.[Start Date]) AS [Start Date], 
  4. Max(DET_Dates.[End Date]) AS [End Date]
  5. FROM DET_Dates INNER JOIN PERSONNEL 
  6. ON DET_Dates.Admin_ID = PERSONNEL.Admin_ID
  7. WHERE (((DET_Dates.TYPE)='vacation'))
  8. GROUP BY PERSONNEL.Admin_ID, DET_Dates.TYPE
Apr 2 '07 #4
Photo
4
Your Awsome, Thanks. That gave me exactly what I needed.



Try this without adding any other fields.

Expand|Select|Wrap|Line Numbers
  1.  
  2. SELECT PERSONNEL.Admin_ID, DET_Dates.TYPE,
  3. Max(DET_Dates.[Start Date]) AS [Start Date], 
  4. Max(DET_Dates.[End Date]) AS [End Date]
  5. FROM DET_Dates INNER JOIN PERSONNEL 
  6. ON DET_Dates.Admin_ID = PERSONNEL.Admin_ID
  7. WHERE (((DET_Dates.TYPE)='vacation'))
  8. GROUP BY PERSONNEL.Admin_ID, DET_Dates.TYPE
Apr 2 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
Your Awsome, Thanks. That gave me exactly what I needed.
You're welcome.
Apr 2 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: David | last post by:
We recently translated the backend db from Access(97) to SQL Server. We are still using Access frontends. I have an update query in the Access front end that uses a lookup table to populate...
30
by: Andante.in.Blue | last post by:
I just browsed through some of my Access links when I came across the Ten Commandments of Access (http://www.mvps.org/access/tencommandments.htm). Some of the points I heartily agree with (and...
2
by: Paul Mendez | last post by:
I really need some help Date Code ConCAT Bal_Fwd NS_Fees Amt_Coll Cur_End_Bal 1/15/2004 KW 11KW2003 $500.00 $250.00 $250.00 2/15/2004 KW 12KW2003 $300.00 $500.00 ...
7
by: Darren | last post by:
I have been attempting to create a reservation planning form in excel that imports Data from an Access database and inserts that information automaticly into the correct spreed sheet and the...
4
by: Bob Alston | last post by:
Some more, rather specific Access performance questions. IN a split front-end & back-end Access/Jet ONLY LAN situation, and with all query criteria fields and join fields indexed: 1. Is is...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
1
MMcCarthy
by: MMcCarthy | last post by:
Access has a number of built-in functions which can be generally used in queries or VBA code. Some of the more common ones are: Note: anything in square brackets is optional Date Functions ...
3
by: Harlequin | last post by:
I must start this posing by making the point that I am NOT a VB programmer and I'm something of a Newbie to MS Access. I can program in a number of languages (Java, Javascript, PERL,PHP and TCL) but...
0
by: uno7031 | last post by:
Help Please!!! Adding 5 Days to another Date in an access query Good Morning, Help please…. I am new to access and trying to write a query that will add 5 days between a RecDate and a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.