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

return a COUNT of records by Week

Status
Not open for further replies.
Mar 20, 2003
103
0
0
AU
I have an asp form that submits customer records to a registration table.

eg
ID,FIRSTNAME, LASTNAME, TSTAMP

Each record is timestamped with getdate()

I need a query that returns the count of records group by WEEK...a start of a week is MONDAY...and end of a week is a SUNDAY.

eg.
START DATE, END DATE, COUNT

Does anyone knows how to do this?
 
The easiest way to do this is to use the datepart function to group by.

Select count(*)
from table
group by datepart(wk, datefield)

The default week is Sunday to Saturday, but you can change it with SET DATEFIRST.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top