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

How can I group information by week?

Status
Not open for further replies.

majorbroncosfan

Programmer
Joined
Feb 23, 2001
Messages
121
Location
US
I'm trying to do an analysis of employee time by week. How can I get that to group in that order? Is that something that would have to be done in something like Crystal Reports?
 
How is the date information stored? Is it a datetime field or is it in integer format? You will want to group by a calculated field which indicates the week. There is no reason why you can't build a query to do that. It would look prettier in Crystal, but you need the ability to run the query for Crystal to work anyway, so you'll have to build it eventually.

Dave Robinder, MCSD
 
Ok, you'll want to derive the week based on the daten and group on the derived week field. The easiest way to do this would probably be to create a lookup table for the weeks of the year. It would include the beginning and end date for each week as well as the week number.

After doing that, try using something similar to the following query:

select week, employeename, sum(hours) from mytable inner join MyWeeks on MyWeeks.BeginDate<=mytable.WorkDate and MyWeeks.EndDate>=mytable.WorkDate Group By employeename, week

Dave Robinder, MCSD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top