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 |
|
durgasubburaman
Starting Member
2 Posts |
Posted - 2003-03-26 : 07:36:46
|
| Dear friendsi have attached select statement for weekly report for us.i hope it simple and best for usSELECT SUM(Freight) AS weeklyfrieghtFROM OrdersWHERE (MONTH(OrderDate) = 3 AND YEAR(OrderDate) = 1997)GROUP BY DATEPART(week, OrderDate)if u have any comments and quiries plese forward to me: durgasubbu@sify.comWe can win in the Hunt.Edited by - merkin on 03/26/2003 08:02:30 |
|
|
Wanderer
Master Smack Fu Yak Hacker
1168 Posts |
Posted - 2003-03-26 : 07:45:20
|
| Ummm .. nope !You need the columsn you group by in the selection criteria:SELECT (DATEPART(week, OrderDate)) as Week, SUM(Freight) AS weeklyfrieght FROM Orders WHERE (MONTH(OrderDate) = 3 AND YEAR(OrderDate) = 1997) GROUP BY DATEPART(week, OrderDate) Here is some sample output from northwind:Week weeklyfrieght ----------- --------------------- 10 315.970011 342.910012 804.350013 198.430014 227.1500Unless you are running this ad hoc , I reckon you'll want to consider having this in a stored procedure, with the month and year as parametre's - otherwise you have to change the code every month.HTH*#* *#* *#* *#* Chaos, Disorder and Panic ... my work is done here! |
 |
|
|
|
|
|