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
 General SQL Server Forums
 New to SQL Server Programming
 Query to sum the amount for a particular category

Author  Topic 

raihan26
Starting Member

8 Posts

Posted - 2011-03-17 : 17:33:51
Is there any way that we can calculate the sum of amount in every category in particular month. Like the way it is show in an image just an example. As I was trying to do with this query but it was not working. Any suggestion will be appreciated.

"SELECT category, SUM(amount) AS OrderTotal FROM budget1 WHERE month='January' "

And I want to do something like this. Any suggestions will be appreciated.

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-17 : 17:38:30
SELECT Month, category, SUM(amount) AS OrderTotal
FROM budget1
GROUP BY Month, category
ORDER BY Month, category
Go to Top of Page

raihan26
Starting Member

8 Posts

Posted - 2011-03-17 : 18:07:04
I have updated the image. What I want is that when I pass month parameter in where clause then it will sum the amount of those category that belong to month in the table.

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-17 : 18:14:18
CREATE PROCEDURE MonthlySummary @month varchar(15) AS
SET NOCOUNT ON
SELECT category, SUM(amount) AS OrderTotal
FROM budget1
WHERE month=@month
GROUP BY Category
Go to Top of Page
   

- Advertisement -