My sql query is:
SELECT DISTINCT
SUBSTRING(DATENAME(MONTH, PostDate), 1, 3) + '-' + CAST(YEAR(PostDate) AS VARCHAR(4)) AS PostArchive,
Posts = COUNT(*)
FROM
Post WHERE Verified=1
GROUP BY
SUBSTRING(DATENAME(MONTH, PostDate), 1, 3) + '-' + CAST(YEAR(PostDate) AS VARCHAR(4)),
YEAR(PostDate), MONTH(PostDate)
ORDER BY PostArchive
Its gives a result like this:
PostArchive Posts ------------------------ Mar-2009 1 Mar-2010 1 May-2005 1 May-2011 1 May-2012 1 May-2013 1
But I want a result order by date(year) like this.
PostArchive Posts ------------------------ May-2005 1 Mar-2009 1 Mar-2010 1 May-2011 1 May-2012 1 May-2013 1
I search and found this link but unable to solve my problem.
I try :
ORDER BY CONVERT(DateTime, PostArchive,101) DESC
But it gives me a error:
Invalid column name 'PostArchive'.
Is there any way to do this or I am in wrong way.Thanks.