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

Grouping data based on weeks

Status
Not open for further replies.

jaybuffet

Technical User
May 22, 2003
31
US
I need a query or SP that groups data by week.

tblNum
Code:
Date        Number
------------------
1/1/03         5
1/3/03         7
1/7/03         2
2/3/03         1
2/5/03         6
etc...

And I want to convert that to

Code:
week               Total
------------------------
1/1/03 - 1/7/03      14
1/8/03 - 1/14/03      0
...
2/1/03 - 2/5/03       7
etc...


Any help would be appreciated

Thanks
Jason
 
Use the datepart function

select datepart(week,week),
total
from table

It will give you the number of the week each value falls on.
From there you will need to write literals.


 
Group By & ranges - exactly what I asked in my first question on this forum:

thread183-420517

If you can't get your solution from that post what you have so far.

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top