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
5 1566 MMcCarthy 14,534
Recognized Expert Moderator MVP
Try this ... -
SELECT AdminID, DET_ID, Detachment_Name, TYPE,
-
Max(Start Date) As Start Date, Max(End Date) As End Date
-
FROM DET_Dates
-
WHERE TYPE = 'VACATION'
-
GROUP BY AdminID, DET_ID, Detachment_Name, TYPE;
-
Mary
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? - 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]
-
FROM DET_Dates INNER JOIN PERSONNEL ON DET_Dates.Admin_ID = PERSONNEL.Admin_ID
-
WHERE (((DET_Dates.TYPE)='vacation'))
-
GROUP BY PERSONNEL.Admin_ID, DET_Dates.DET_ID, DET_Dates.Detachment_Name, DET_Dates.TYPE
Photo
MMcCarthy 14,534
Recognized Expert Moderator MVP
Try this without adding any other fields. -
-
SELECT PERSONNEL.Admin_ID, DET_Dates.TYPE,
-
Max(DET_Dates.[Start Date]) AS [Start Date],
-
Max(DET_Dates.[End Date]) AS [End Date]
-
FROM DET_Dates INNER JOIN PERSONNEL
-
ON DET_Dates.Admin_ID = PERSONNEL.Admin_ID
-
WHERE (((DET_Dates.TYPE)='vacation'))
-
GROUP BY PERSONNEL.Admin_ID, DET_Dates.TYPE
Your Awsome, Thanks. That gave me exactly what I needed.
Try this without adding any other fields. -
-
SELECT PERSONNEL.Admin_ID, DET_Dates.TYPE,
-
Max(DET_Dates.[Start Date]) AS [Start Date],
-
Max(DET_Dates.[End Date]) AS [End Date]
-
FROM DET_Dates INNER JOIN PERSONNEL
-
ON DET_Dates.Admin_ID = PERSONNEL.Admin_ID
-
WHERE (((DET_Dates.TYPE)='vacation'))
-
GROUP BY PERSONNEL.Admin_ID, DET_Dates.TYPE
MMcCarthy 14,534
Recognized Expert Moderator MVP
Your Awsome, Thanks. That gave me exactly what I needed.
You're welcome.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 fields. The
common fields between the table and the lookup table are the primary
key (LocID) and date & time fields. The query is:
UPDATE tblPT_Offsets INNER JOIN tblPT ON tblPT_Offsets.LocID =
tblPT.LocID SET tblPT.Offset_ft = .,
tblPT.Salinity =...
|
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 wish that my predecessor had followed) but
-- alas -- being a relative beginner to Access, I can't see the
reasoning behind one of the points and the site does not provide any
rationale / explanation for its presence either:
2. Thou shalt never...
|
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 -$200.00
3/15/2004 KW 1KW2004 ???? $123.00 $584.00 -$461.00
4/15/2001 KW 2KW2004 XXXX $223.00 $484.00 -$261.00
1/15/2004 SO 11O2003 $300.00 $250.00 $50.00
2/15/2004 SO 12SO2003 $300.00 $500.00 -$200.00...
|
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 correct cells within
that worksheet. The Excel Book is made up of 12 worksheets named
Jan-Dec. Each worksheet has columns labeled as each day of that month.
Column 'A' is reserved for 19 rows named "room1 - room19". The data I
am importing from the...
|
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 good form to have a single query with base table with criteria
joined to a related table - all in one query? Or should I do a
two-step, first query does selection of main table and then join with
other table?
2. I have a table with multiple...
| |
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 2005, and, since he already has
licenses for Office Pro 2002, he wants to upgrade to that.
I've been saying that we need to upgrade to Access 2003, not 2002, even if
Office is kept at 2002. We are also looking to do a fair amount of...
|
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
Date() - Returns the current system date
Now() - Returns the current system timestamp (date and time)
|
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 have never actually learnt VB so my request is that you bear this in mind if you plan on replying to this post.
My request for help is as follows:
I have an MS Access database in which one of the tables within it contains two date fields called...
|
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 DLPayDate
I created the query in design view of access.
Current Query: SELECT PaymentCalculator2.ID, PaymentCalculator2.RecDate, DateAdd("w",5+1,) AS DLPayDate, DateAdd("w",5,) AS DLPayDate2
FROM PaymentCalculator2
WHERE...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |