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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 weekly report in sql server

Author  Topic 

durgasubburaman
Starting Member

2 Posts

Posted - 2003-03-26 : 07:36:46
Dear friends
i have attached select statement for weekly report for us.
i hope it simple and best for us

SELECT SUM(Freight) AS weeklyfrieght
FROM Orders
WHERE (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.com

We 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.9700
11 342.9100
12 804.3500
13 198.4300
14 227.1500


Unless 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!
Go to Top of Page
   

- Advertisement -