I can't figure out how to do this.

S

SF

Hi,

I can't figure out how to do this. I want to check if staff is available in
the office by create query from TravelTable (TravelID, EmployeeID,
TravelDateFrom, TravelDateTo).
The query should list anyone who are not travelling today. Would it be
possible or not?

SF
 
Joined
Dec 17, 2007
Messages
57
Reaction score
0
This query should work:

SELECT EmployeeId
, TravelDateFrom
, TravelDateTo
, "In OFFICE" AS Status
FROM TravelTable
WHERE
TravelDateFrom Is Not Null AND
TravelDateTo Is Not Null AND
Date() Not Between [TravelDateFrom] And [TravelDateTo];
 
K

Krzysztof Naworyta

SF wrote:

| I can't figure out how to do this. I want to check if staff is
| available in the office by create query from TravelTable (TravelID,
| EmployeeID, TravelDateFrom, TravelDateTo).
| The query should list anyone who are not travelling today. Would it be
| possible or not?

It is possible :)
 
J

John Spencer

Assuming you have an Employee table, this is possible

The basic idea is to create a query that shows everyone that IS traveling on
the date specified and then use that query to get everyone that is not traveling.

This query should get everyone that is traveling today
SELECT EmployeeID
FROM TravelTable
WHERE Date() Between TravelDateFrom and TravelDateTo

So, the following should work to give you employees not traveling.

SELECT *
FROM EmployeeTable
WHERE EmployeeID NOT IN
(SELECT EmployeeID
FROM TravelTable
WHERE Date() Between TravelDateFrom and TravelDateTo)

You can also use
SELECT *
FROM EmployeeTable
WHERE EmployeeID NOT EXISTS
(SELECT *
FROM TravelTable
WHERE Date() Between TravelDateFrom and TravelDateTo
AND TravelTable.EmployeeID = EmployeeTable.EmployeeID)

Or other variations are available.

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

SF

Thank you for your tip. I will try that.

SF


John Spencer said:
Assuming you have an Employee table, this is possible

The basic idea is to create a query that shows everyone that IS traveling
on the date specified and then use that query to get everyone that is not
traveling.

This query should get everyone that is traveling today
SELECT EmployeeID
FROM TravelTable
WHERE Date() Between TravelDateFrom and TravelDateTo

So, the following should work to give you employees not traveling.

SELECT *
FROM EmployeeTable
WHERE EmployeeID NOT IN
(SELECT EmployeeID
FROM TravelTable
WHERE Date() Between TravelDateFrom and TravelDateTo)

You can also use
SELECT *
FROM EmployeeTable
WHERE EmployeeID NOT EXISTS
(SELECT *
FROM TravelTable
WHERE Date() Between TravelDateFrom and TravelDateTo
AND TravelTable.EmployeeID = EmployeeTable.EmployeeID)

Or other variations are available.

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

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