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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date problem

Status
Not open for further replies.

lcan

Technical User
Joined
Mar 1, 2003
Messages
5
Location
US
I am trying to get a count of Employees for each month of the year. 1. I am having to do seperate queries for each month (with grouping for Date and Identifier and a Count for Employee)for each table 2. then making a table with those numbers and 3. then querying just Employee for a Count. Is there a simpler way to do this with so many queries and tables????

Employee Date Identifier
John Smith Between 1/1/2002 and 1/31/2002 2222
 
You'll need to change column/table names etc but try something like this:

select [myEmp], format([myDate], "mm/yy") as mDate, [myId], count([myEmp])
from myTable
group by [myEmp], format([myDate], "mm/yy"), [myId]

or if you want to keep as a date/time column:

select [myEmp], dateserial(Year([myDate]), Month([myDate]), 1) as mDate, [myId], count([myEmp])
from myTable
group by [myEmp], dateserial(Year([myDate]), Month([myDate]), 1), [myId]

' converts all dates to 1st of month Best Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top