SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 divide recordset to weeks
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

esthera
Flowing Fount of Yak Knowledge

1388 Posts

Posted - 09/16/2013 :  07:15:41  Show Profile  Reply with Quote
I have a recordset that returns a whole months data

I want to divide it to 4 recordsets (or how ever many weeks there are)

with each weeek

my recordset is
Date (datetime)
Total (integer) and I want to divide this up to 4 recordsets by date

what's the best way to do this?

SwePeso
Patron Saint of Lost Yaks

Sweden
30117 Posts

Posted - 09/16/2013 :  07:27:59  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT      DATEADD(DAY, DATEDIFF(DAY, '19000101', [Date]) / 7 * 7, '19000101'),
            SUM(Total) AS Total
FROM        dbo.Table1
WHERE       [Date] BETWEEN '20130901' AND '20130930'
GROUP BY    DATEADD(DAY, DATEDIFF(DAY, '19000101', [Date]) / 7 * 7, '19000101');



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

esthera
Flowing Fount of Yak Knowledge

1388 Posts

Posted - 09/16/2013 :  08:06:30  Show Profile  Reply with Quote
thanks what i need is actually 4 recordset

one for each week

showing

sunday 50
monday 45

etc


and then same for each week of the month
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30117 Posts

Posted - 09/16/2013 :  08:45:36  Show Profile  Visit SwePeso's Homepage  Reply with Quote
It's still a GROUP BY operation.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000