querying unrelated tables

K

Keith

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
 
J

Jeff Boyce

Keith

It sounds like you are saying that you want to see each employeeID and each
date (on the "PunchTime" table), plus the time in/out if the date is not a
holiday, and the holiday's name if it is.

Note that I'm assuming that your punchtime table contains DATES as well as
times...

If that's an accurate paraphrase, then one approach would be to:

1. create a new query
2. add both tables
3. put the punchtime table fields in the output of the query
4. add one more output field to the query, containing something like
(untest):

HolidayName: IIF(PunchDate = HolidayDate, [HolidayName], "")

You'd need to adjust this to match your fieldnames...

Good Luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.
 
K

KARL DEWEY

You should not use Date as a field name as it can give you problems.
Try these two queries --
UNTESTED --- UNTESTED --
qryEmpAllDate --
SELECT Employee_PunchTime.EmpID, Employee_PunchTime.[Date] AS AllDate
FROM Employee_PunchTime, Holidays
GROUP BY Employee_PunchTime.EmpID, Employee_PunchTime.[Date]
UNION SELECT Employee_PunchTime.EmpID, Holidays.[Date]
FROM Employee_PunchTime, Holidays
GROUP BY Employee_PunchTime.EmpID, Holidays.[Date];

SELECT qryEmpAllDate.EmpID, Employee_PunchTime.[Time-in],
Employee_PunchTime.[Time-out], qryEmpAllDate.AllDate, [Paid Holiday]
FROM (qryEmpAllDate LEFT JOIN Employee_PunchTime ON qryEmpAllDate.EmpID =
Employee_PunchTime.EmpID AND qryEmpAllDate.AllDate =
Employee_PunchTime.[Date]) LEFT JOIN Holidays.Holiday ON
qryEmpAllDate.AllDate = Holidays.[Date];
 
J

John Spencer

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
 
K

Keith

Thanks Jeff.

I understand your logic, however, in your "HolidayName: IIF(PunchDate =
HolidayDate, [HolidayName], "")" statement, PunchDate will never equal
HolidayDate because no one would have punched-in or out on the holiday.

Does this make sense?

Jeff Boyce said:
Keith

It sounds like you are saying that you want to see each employeeID and each
date (on the "PunchTime" table), plus the time in/out if the date is not a
holiday, and the holiday's name if it is.

Note that I'm assuming that your punchtime table contains DATES as well as
times...

If that's an accurate paraphrase, then one approach would be to:

1. create a new query
2. add both tables
3. put the punchtime table fields in the output of the query
4. add one more output field to the query, containing something like
(untest):

HolidayName: IIF(PunchDate = HolidayDate, [HolidayName], "")

You'd need to adjust this to match your fieldnames...

Good Luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Keith said:
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


.
 
J

Jeff Boyce

Keith

So you're saying that the daterange does NOT have "empties" for the dates
that are holidays, counter to my assumption.

I didn't see anything describing where you are storing the "pay period".
Unless you have that, how will you (or Access) know where to look for
"holidays"?

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Keith said:
Thanks Jeff.

I understand your logic, however, in your "HolidayName: IIF(PunchDate =
HolidayDate, [HolidayName], "")" statement, PunchDate will never equal
HolidayDate because no one would have punched-in or out on the holiday.

Does this make sense?

Jeff Boyce said:
Keith

It sounds like you are saying that you want to see each employeeID and
each
date (on the "PunchTime" table), plus the time in/out if the date is not
a
holiday, and the holiday's name if it is.

Note that I'm assuming that your punchtime table contains DATES as well
as
times...

If that's an accurate paraphrase, then one approach would be to:

1. create a new query
2. add both tables
3. put the punchtime table fields in the output of the query
4. add one more output field to the query, containing something like
(untest):

HolidayName: IIF(PunchDate = HolidayDate, [HolidayName], "")

You'd need to adjust this to match your fieldnames...

Good Luck!

Regards

Jeff Boyce
Microsoft Access MVP

--
Disclaimer: This author may have received products and services mentioned
in this post. Mention and/or description of a product or service herein
does not constitute endorsement thereof.

Any code or pseudocode included in this post is offered "as is", with no
guarantee as to suitability.

You can thank the FTC of the USA for making this disclaimer
possible/necessary.

Keith said:
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


.
 
J

John Spencer

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 said:
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
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
 
K

Keith

Thank you John.

Your suggestion seems to to work. I just need to tweak the query a little to
suit to my tables.

Thanks again.

John Spencer said:
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 said:
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
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
.
 

Ask a Question

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.

Ask a Question

Top