SQL Date Query

Hi All following from a recent post i now need to add a number associated with each month so that i can sort them from January To Feruary the query is below

SELECT     TOP (100) PERCENT DATENAME(month, createdon) + DATENAME(year, createdon) AS Month, projcode, result, COUNT(*) AS Expr2
FROM         dbo.dmsproj
GROUP BY DATENAME(month, createdon) + DATENAME(year, createdon), projcode, result

Thank You

John
pepps11976Asked:
Who is Participating?
 
BauersachsCommented:
Use
GROUP BY createdon, DATENAME(month, createdon) + DATENAME(year, createdon), projcode, result
instead
0
 
Pratima PharandeCommented:
you want to order the ntry this

SELECT     TOP (100) PERCENT DATENAME(month, createdon) + DATENAME(year, createdon) AS Month, projcode, result, COUNT(*) AS Expr2
FROM         dbo.dmsproj
GROUP BY DATENAME(month, createdon) + DATENAME(year, createdon), projcode, result
order by year(createdon) , month(createdon)
0
 
Alpesh PatelAssistant ConsultantCommented:
yes she (pratima_mcs:) is right.

First year and Month. Because, Month is repeated.
0
 
pepps11976Author Commented:
Hi I tried the query but it failed with

Column dbo.dmsproj.createdon is invalid in the order by clause because it is not contained in either an aggregate function or the group by clause
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.