Okay, the question is mildly misleading… I know a couple different ways to get the MMYYYY format from a date, but it requires converting the string into VARCHAR. While that’s all fine and dandy, ordering the results is where it becomes a real pain.
Here’s what I’m using:
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 appear 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’m trying them to order by the date ascending. As you can see, they do not… Is there a way to get what I’m trying to achieve?
Thanks in advance!
1 Answer