View Single Post
  #7  
Old June 3rd, 2010, 08:36 PM posted to microsoft.public.access.queries
John Spencer
external usenet poster
 
Posts: 7,815
Default querying unrelated tables

Might help if I included the table name
Parameters [Period Start] as DateTime, [Period End] as DateTime;
SELECT EmpID, [Date], [Time-In], [Time-out], Null as [Paid Holiday]
FROM Employee_PunchTime
WHERE [Date] Between [Period Start] and [Period End]
UNION
SELECT EmpID, HolidayDate, Null, Null, HolidayName
FROM Employees, Holidays
WHERE HolidayDate Between [Period Start] and [Period End]


John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

John Spencer wrote:
Best I can think of right now is a Union query

Parameters [Period Start] as DateTime, [Period End] as DateTime;
SELECT EmpID, [Date], [Time-In], [Time-out], Null as [Paid Holiday]
FROM
WHERE [Date] Between [Period Start] and [Period End]
UNION
SELECT EmpID, HolidayDate, Null, Null, HolidayName
FROM Employees, Holidays
WHERE HolidayDate Between [Period Start] and [Period End]

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Keith wrote:
I have two tables - Employee_PunchTime table and Holidays Table. The
PunchTime table contains three fields representing EmployeeID, Time-in
and Time-out; and the Holiday table contains two fields representing
name of holiday and the date.
If the payroll period is 5/31/2010 (Mon) thru 6/4/2010 (Fri) and
5/31/2010 is a paid holiday, I need to create a query that shows
punched time and paid holiday on a separate column.

On the paid holiday, there would obviously be no Time-In and Time-Out
record.

It will look something like this:

EmpID Date Time-in Time-out Paid Holiday
------- ---- -------- --------- ------------ 1001
5/31/10 Memorial Day
1001 6/01/10 9:00 am 6:00 pm
1001 6/02/10 9:00 am 6:00 pm
1001 6/03/10 9:00 am 6:00 pm
1001 6/02/10 9:00 am 6:00 pm

Any suggestions?

Thank you.

Keith