SQL Query Group By Months

Hi All

I have the following query in SQL

SELECT     createdon, projcode, result
FROM         dbo.dmsproj

The createdon column consists Ranging From 2000-12-20 - Current date

Can anybody help me Group These dates into Month Name ie: January, February etc



Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Patrick MatthewsCommented:

What sort of results are you after?

pepps11976Author Commented:
I need yo create a bar graph out of the data so i need to group all the dates into Months

The raw data looks like this

Createdon                Projcode                   Result
2009-12-07             OPP002                      WIP
2009-12-08             OPP003                      WON
2009-12-09             OPP004                      LOST
2009-12-10             OPP005                      Lost
2009-12-11             OPP006                      WON

there is about 2000 results like this and i need to build a bar graph to show over the years orders we have won lost or are working on.

to get the month name === >DATENAME(month, createdon)

try something like this...

SELECT      DATENAME(month, createdon),count(*)
FROM         dbo.dmsproj
group by DATENAME(month, createdon)
IT Pros Agree: AI and Machine Learning Key

We’d all like to think our company’s data is well protected, but when you ask IT professionals they admit the data probably is not as safe as it could be.

pepps11976Author Commented:
Ok Thats goo but how can i add the year onto the end of the month
pepps11976Author Commented:
i was going to use excel but i need it in sql so that i can display as dashboard
SELECT      DATENAME(month, createdon) + DATENAME(year, createdon), projcode, result,count(*)
FROM         dbo.dmsproj
group by DATENAME(month, createdon) + DATENAME(year, createdon) ,projcode, result

check this out for more reference...

pepps11976Author Commented:
Perfect thankyou i will issue points

Just one more quick question it may mean reposting

But if i wanted to do a rolling twelve months from current month back 12 months, is this possible or shall i post another question.

Thanks Again

< But if i wanted to do a rolling twelve months from current month back 12 months, is this possible or shall i post another question

Yes. its possible. You could use DATEADD function to achieve that result.

Please post another question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.