Count products sold for each of the last twelve months by customer in SQL2005

I need to create a select statement that will produce one row for each customer that counts the products from each of the last twelve months.

The row for each customer would look something like the following.

Customer name
March-2011 (Total products sold)
February-2011 (Total products sold)
January-2011 (Total products sold)
December-2010 (Total products sold)
November-2010 (Total products sold)
October-2010 (Total products sold)
September-2010 (Total products sold)
August-2010 (Total products sold)
July-2010 (Total products sold)
June-2010 (Total products sold)
May-2010 (Total products sold)
April-2010 (Total products sold)


How would I create a select statment to create an export in the avbove format?
jdr0606Asked:
Who is Participating?
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.

Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
SELECT CUSTOMER_NAME, iMONTH, COUNT(PRODUCT) FROM TABLENAME
WHERE CUSTOMER_NAME='SearchCriteria'
GROUP BY CUSTOMER_NAME, iMONTH

Open in new window

0
jdr0606Author Commented:
Except I want each row to look like
CustomerName, January, February, March etc.
0
Rikin ShahMicrosoft Dynamics CRM ConsultantCommented:
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Bhavesh ShahLead AnalysistCommented:
Hi,

check out this

- Bhavesh
SELECT CustomerName,
		DATENAME(Month,SalesDate)+'-'+Cast(Year(SalesDate)as Varchar(4)) + '('+Cast(Count(Product)as varchar(5))+')'as ProductSale
From TableName
Group by CustomerName, SalesDate

Open in new window

0
Bhavesh ShahLead AnalysistCommented:
0
Alpesh PatelAssistant ConsultantCommented:
Hi Basic is :SELECT CUSTOMER_NAME, iMONTH, COUNT(PRODUCT) FROM TABLENAME
WHERE CUSTOMER_NAME='SearchCriteria'
GROUP BY CUSTOMER_NAME, iMONTH

Plus use Pivot Table

SELECT *
FROM (
 SELECT CUSTOMER_NAME, iMONTH, COUNT(PRODUCT) FROM TABLENAME
WHERE CUSTOMER_NAME='SearchCriteria'
GROUP BY CUSTOMER_NAME, iMONTH
) TableDate
PIVOT (
   COUNT(PRODUCT)
  FOR iMONTH IN (
    [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]
  )
) PivotTable
0

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 2005

From novice to tech pro — start learning today.

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.