Well, the question is mildly misleading ... I know a couple of different ways to get the MMYYYY format from a date, but this requires converting the string to VARCHAR. While everything is beautiful and dandy, ordering the results, where it becomes a real pain.
Here is what I use:
SELECT
CONVERT(VARCHAR(2),MONTH(TransactionDte)) + '/' + CONVERT(VARCHAR(4),YEAR(TransactionDte) AS MMYYYY
,SUM(TransactionCt) AS TransCt
,SUM(TransactionAmt) AS TransAmt
FROM Transactions
GROUP BY CONVERT(VARCHAR(2),MONTH(TransactionDte)) + '/' + CONVERT(VARCHAR(4),YEAR(TransactionDte)
The results are as follows:
1/2010
1/2011
10/2010
10/2011
11/2010
11/2011
12/2010
12/2011
2/2010
2/2011
3/2010
3/2011
etc.
I try to sort them by date in ascending order. As you can see, they are not ... Is there a way to get what I'm trying to achieve?
Thanks in advance!