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 |
|
alanhuro
Starting Member
34 Posts |
Posted - 2008-07-31 : 15:17:42
|
| Hello To all Sequel Genius out there,Yearly, monthly and daily report are easy to generate by using group by function. How do you generate a weekly report? Assume I haveDate__________Cat__________Value2008-07-01_____A____________302008-07-02_____A____________202008-07-02_____B____________102008-07-03_____A____________602008-07-04_____A____________802008-07-04_____C____________3302008-07-05_____A____________2302008-07-06_____B____________3302008-07-07_____A____________7302008-07-08_____B____________3302008-07-10_____A____________130It would be nice to have a report having format like this. The date start begin on monday. The report output should look like thisDate___________Cat__________Sum2008-07-01_____A____________4202008-07-01_____B____________3402008-07-01_____C____________3302008-07-07_____A____________8602008-07-07_____B____________330Thanks |
|
|
elancaster
A very urgent SQL Yakette
1208 Posts |
Posted - 2008-07-31 : 17:04:49
|
| look at the datepart function on books online, you can group by week number. that should give you a head startEm |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-07-31 : 17:09:12
|
[code]SELECT DATEADD(WEEK, DATEDIFF(WEEK, '19000101', Date), '19000101'),Cat, SUM(Value)FROM Table1GROUP BY DATEADD(WEEK, DATEDIFF(WEEK, '19000101', Date), '19000101')ORDER BY DATEADD(WEEK, DATEDIFF(WEEK, '19000101', Date), '19000101')[/code] E 12°55'05.25"N 56°04'39.16" |
 |
|
|
Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)
7020 Posts |
Posted - 2008-07-31 : 18:31:58
|
| Wouldn't 2008-07-01 and 2008-07-07 be in the same week? They are only 6 days apart.CODO ERGO SUM |
 |
|
|
alanhuro
Starting Member
34 Posts |
Posted - 2008-08-01 : 08:46:38
|
| Thanks Peso and elancasterI did not now that simple. I also set @@Datefirst to monday and it works great.Thanks |
 |
|
|
|
|
|
|
|