Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2013-09-16 : 07:15:41
|
I have a recordset that returns a whole months dataI want to divide it to 4 recordsets (or how ever many weeks there are)with each weeekmy recordset is Date (datetime)Total (integer) and I want to divide this up to 4 recordsets by datewhat's the best way to do this? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-16 : 07:27:59
|
[code]SELECT DATEADD(DAY, DATEDIFF(DAY, '19000101', [Date]) / 7 * 7, '19000101'), SUM(Total) AS TotalFROM dbo.Table1WHERE [Date] BETWEEN '20130901' AND '20130930'GROUP BY DATEADD(DAY, DATEDIFF(DAY, '19000101', [Date]) / 7 * 7, '19000101');[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
esthera
Master Smack Fu Yak Hacker
1410 Posts |
Posted - 2013-09-16 : 08:06:30
|
thanks what i need is actually 4 recordset one for each week showing sunday 50monday 45etc and then same for each week of the month |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2013-09-16 : 08:45:36
|
It's still a GROUP BY operation. Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|
|
|