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 |
|
d
Starting Member
26 Posts |
Posted - 2005-07-08 : 05:55:38
|
HelloHere is my query:SELECT TOP 100 PERCENT DATENAME(mm, ExpectedDeliveryDate) AS [Month], COUNT(AmountOfLoan) AS [Count], SUM(AmountOfLoan) AS [Value]FROM dbo.ProposalsWHERE (ExpectedDeliveryDate IS NOT NULL) AND (ExpectedDeliveryDate > GETDATE())GROUP BY DATENAME(mm, ExpectedDeliveryDate), AmountOfLoan WITH rollupHere is my result: August 1 7990.45 August 1 13500 August 1 14837.44 August 3 36327.89 July 1 4000 July 1 7118 July 1 7575.82 July 1 8000 July 1 10000 July 1 11339.34 July 1 12722.57 July 1 15137.67 July 1 15775 July 1 16000 July 1 17336 July 1 24928 July 12 149932.4 October 1 11027.19 October 1 17500 October 2 28527.19 September 1 8800 September 1 17637.73 September 2 26437.73 19 241225.21How do I get it to 1) Display in Month name order and 2) Get it to total the months so that I only have four months showing with a count and total result??Any help appreciated, many thanks in advance  |
|
|
mwjdavidson
Aged Yak Warrior
735 Posts |
Posted - 2005-07-08 : 06:06:56
|
| Put an ORDER BY clause in (nb. if you order by month name, the order will be alphabetical so you will probably want to order by month number). Remove AmountOfLoan from the GROUP BY clause.Is the year not important? |
 |
|
|
d
Starting Member
26 Posts |
Posted - 2005-07-08 : 06:18:19
|
That's great. Removing the amountofloan gives me what I want, however add in the year or month integer to order by it duplicates the months, because of the roll up i think.This is what i have now:SELECT TOP 100 PERCENT DATENAME(mm, ExpectedDeliveryDate) AS [Month], COUNT(AmountOfLoan) AS [Count], SUM(AmountOfLoan) AS [Value]FROM dbo.ProposalsWHERE (ExpectedDeliveryDate IS NOT NULL) AND (ExpectedDeliveryDate > GETDATE())GROUP BY DATENAME(mm, ExpectedDeliveryDate) WITH rollupResults:Month Count ValueAugust 3 36327.89July 12 149932.4October 2 28527.19September 2 26437.73 19 241225.21 How would I get it to include year and order correctly without it looking like:SELECT TOP 100 PERCENT MONTH(ExpectedDeliveryDate) AS Expr1, DATENAME(mm, ExpectedDeliveryDate) AS [Month], COUNT(AmountOfLoan) AS [Count], SUM(AmountOfLoan) AS [Value]FROM dbo.ProposalsWHERE (ExpectedDeliveryDate IS NOT NULL) AND (ExpectedDeliveryDate > GETDATE())GROUP BY MONTH(ExpectedDeliveryDate), DATENAME(mm, ExpectedDeliveryDate) WITH rollupORDER BY MONTH(ExpectedDeliveryDate)Expr1 Month Count Value 19 241225.217 July 12 149932.47 12 149932.48 August 3 36327.898 3 36327.899 September 2 26437.739 2 26437.7310 October 2 28527.1910 2 28527.19 Thanks again in advance |
 |
|
|
|
|
|
|
|