Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need help with selecting some but not others.

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
having difficulty with the "AND" "OR"

I want to select
Regular Hours
General Office/Admin (non bill)

but not select
Sick Hours
Holiday Hours
Vacation Hours

here is my query
Code:
SELECT [TimeSheet Details].[Employee Name], Sum([TimeSheet Details].Hours) AS SumOfHours, [TimeSheet Details].TypeOfHours, [TimeSheet Details].WeekEndDate, [TimeSheet Details].OverTime, [TimeSheet Details].TypeOfHours
FROM [TimeSheet Details]
GROUP BY [TimeSheet Details].[Employee Name], [TimeSheet Details].TypeOfHours, [TimeSheet Details].WeekEndDate, [TimeSheet Details].OverTime, [TimeSheet Details].PeriodEndDate, [TimeSheet Details].TypeOfHours
HAVING ((([TimeSheet Details].TypeOfHours)<>"Sick Hours" Or ([TimeSheet Details].TypeOfHours)<>"Vacation Hours" Or ([TimeSheet Details].TypeOfHours)<>"Holiday Hours") AND (([TimeSheet Details].OverTime)=False) AND (([TimeSheet Details].PeriodEndDate)=[Forms]![frmTotals]![cboPeriodEndDate]) AND (([TimeSheet Details].TypeOfHours)="General Office/Admin (non bill)"))
ORDER BY [TimeSheet Details].[Employee Name], [TimeSheet Details].WeekEndDate;

TIA

DougP
 

you don't state how the overtime should be handled...is it no overtime for all types or just some types?

maybe:

Code:
SELECT [Employee Name], Sum(Hours) AS SumOfHours, TypeOfHours, WeekEndDate, OverTime, TypeOfHours
FROM [TimeSheet Details]
WHERE TypeOfHours NOT IN ("Sick Hours", "Holiday Hours", "Vacation Hours") AND OverTime=False AND PeriodEndDate=[Forms]![frmTotals]![cboPeriodEndDate] AND TypeOfHours="General Office/Admin (non bill)"
GROUP BY [Employee Name], TypeOfHours, WeekEndDate, OverTime, PeriodEndDate, TypeOfHours
ORDER BY [Employee Name], WeekEndDate;


Leslie

Have you met Hardy Heron?
 
This clause seems irrelevant
Code:
TypeOfHours<>"Sick Hours" Or 
TypeOfHours<>"Vacation Hours" Or 
TypeOfHours<>"Holiday Hours"
TypeOfHours will always be not equal to at least two of those strings so the clause will always be TRUE.

Besides
Code:
TypeOfHours="General Office/Admin (non bill)"
will exclude all other values anyway.

You do need to use a WHERE clause as Leslie has done. HAVING is processed after the GROUP BY and it works on the grouped records ... not the records in the table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top