Dave E said:
Chris, I hope the information below is what you want, this is
what
the Access
Documenter has for the table.
I currently do not have a query designed for this but what I am trying to do
is create a query from all of the employment records that shows how long a
person has gone with out employment between jobs. My goal for this query is
to use it as part of a report that needs to show all people that have been
employed continiously for 90 days ofer a period of time (coutiniously means
no gaps in employment greater than 30 days). I also need to show the people
that have been employed 180 days coutiniously (Again defined as
no
gaps in
employment greater than 30 days.) over the same period of time
The report periods come from a form
Form name [Report Menu]
Start date field name [Beginning]
End date field name [To]
My problem is compairing one Employment record term date to the next records
Employment hire date. so that I can see how many days the person was
unemployed, or transversly if in a 180 day or 90 day period if they were
"continously" employed.
***** This is Table field Discription per the Documenter *****
The documenter produces information that is practically impossible
to read, which is why I did not mention it.
C:\Documents and Settings\dave\Desktop\Database Develop
Thursday,
December
08, 2005
Table: Employment Information Page: 1
Columns
Name Type Size
title Text 50
SSN Long Integer 4
UPATE ID Long Integer 4
DATE OF UPDATE Date/Time 8
REFERAL DATE Date/Time 8
EMPLOYER Text 50
EMP PHONE Text 50
HIRE DATE Date/Time 8
TERM DATE Date/Time 8
$ PER HR Currency 8
HOURS PER WEEK Long Integer 4
BENIFITS Text 50
This is an example of the data
SSN Hire date Term date
11111 1/1/05 2/1/05 *
11111 1/7/05 4/1/05 * note the overlap in employment
Ouch! Well, I had thought it was going to be easy.
Eliminating overlapping dates! You don't ask for the easy things,
do you!
<snip>
My apologies, I didn't use your column and table names. I filched
off of some existing example tables I already had. This should
still be fully adaptable to your purposes.
Project to count the number of consecutive days of employement.
Tables:
CREATE TABLE Employees
(EmployeeID INTEGER
,SSN CHAR(10)
,FName TEXT(72)
,LName TEXT(72)
,CONSTRAINT pk_piEmployees
PRIMARY KEY (EmployeeID)
)
CREATE TABLE Jobs
(JobID INTEGER
,JobName TEXT(72)
,JobDescription TEXT(255)
,CONSTRAINT pk_piJobs
PRIMARY KEY (JobID)
)
CREATE TABLE EmploymentHistory
(EmploymentHistoryID INTEGER
,EmployeeID INTEGER
,JobID INTEGER
,StartDate DATETIME
,EndDate DATETIME
,CONSTRAINT pk_EmployeeHistory
PRIMARY KEY (EmploymentHistoryID)
,CONSTRAINT fk_EmploymentHistory_Employees_EmployeeID
FOREIGN KEY (EmployeeID)
REFERENCES Employees (EmployeeID)
,CONSTRAINT fk_EmploymentHistory_Jobs_JobID
FOREIGN KEY (JobID)
REFERENCES Jobs (JobID)
)
Sample Data:
Empoloyees:
1, 1112223333, Jay, Smith
2, 4445556666, Dee, Smith
3, 7778889999, Jeff, Smith
Jobs:
1, Sewer Cleaner, You don't want to know
2, Sewer Backup Supervisor, Still bad
3, Sewer Supervisor, Not much better
4, Sewer Backup Inspector, Lousy
5, Sewer Inspector, Not really that good
6, Sewer Management, King of all he surveys (uh oh . . .)
EmploymentHistory
1, 1, 1, 01/01/2000, 01/01/2001
2, 1, 2, 06/15/2000, 12/31/2000
3, 1, 3, 01/01/2001, 12/31/2001
4, 1, 4, 03/15/2001, 10/15/2001
5, 1, 5, 01/01/2002, 12/31/2002
6, 1, 5, 01/01/2004, 12/31/2004
7, 2, 5, 01/01/2001, 12/31/2004
8, 3, 6, 01/01/2000, null
Desired Results
#1
EmployeeID, StartDate, EndDate
1, 01/01/2000, 12/31/2002
1, 01/01/2004, 12/31/2004
2, 01/01/2001, 12/31/2004
3, 01/01/2000, 12/09/2005
#2
EmployeeID, ConsecutiveDaysEmployed
1 1462
2 1461
3 2170
This first query gets pretty wide, I tried shoving things over to
the left as far as reasonable, and I apologize for any line-wrapping
that might occur.
Query:
EliminateOverlappingDates:
SELECT EH1.EmployeeID
,EH1.StartDate
,MIN(EH2.EndDate) AS EndDate
FROM
(SELECT EH01.EmployeeID
,EH01.StartDate
FROM EmploymentHistory AS EH01
WHERE NOT EXISTS
(SELECT *
FROM EmploymentHistory EH001
WHERE EH001.EmployeeID = EH01.EmployeeID
AND EH001.StartDate < EH01.StartDate
AND Nz(EH001.EndDate, CDate(Date())) >=
(EH01.StartDate - 1)
)
) AS EH1
INNER JOIN
(SELECT EH02.EmployeeID
,Nz(EH02.EndDate, CDate(Date())) AS EndDate
FROM EmploymentHistory AS EH02
WHERE NOT EXISTS
(SELECT *
FROM EmploymentHistory AS EH002
WHERE EH002.EmployeeID = EH02.EmployeeID
AND EH002.StartDate <=
Nz(EH02.EndDate + 1, CDate(Date()))
AND Nz(EH002.EndDate, CDate(Date())) >
Nz(EH02.EndDate, CDate(Date()))
)
) AS EH2
ON EH1.EmployeeID = EH2.EmployeeID
AND EH1.StartDate < EH2.EndDate
GROUP BY EH1.EmployeeID
,EH1.StartDate
Results #1
EmployeeID, StartDate, EndDate
1, 01/01/2000, 12/31/2002
1, 01/01/2004, 12/31/2004
2, 01/01/2001, 12/31/2004
3, 01/01/2000, 12/09/2005
ConsecutiveEmploymentDays:
SELECT EOD1.EmployeeID
,SUM(DateDiff("d", EOD1.StartDate - 1, EOD1.EndDate))
AS ConsecutiveDaysEmployed
FROM EliminateOverlappingDates AS EOD1
GROUP BY EOD1.EmployeeID
Results #2
EmployeeID, ConsecutiveDaysEmployed
1 1462
2 1461
3 2170
Well, it isn't pretty, but it gets the job done.
Sincerely,
Chris O.