?
Solved

MS Access Crosstab Query -- column headings that display year and month across multiple years

Posted on 2009-04-13
9
Medium Priority
?
1,299 Views
Last Modified: 2012-06-27
I'd like to create a multi-year crosstab query that looks like this:

                                     2008 Nov     2008 Dec     2009 Jan    2009 Feb
            Group 1
            Group 2
            Group 3

I know how to do this for "quarters" (e.g., 2008 Q2), but I can't seem to find a way to do it for "months."
0
Comment
Question by:WallyTee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 24129799
Continuing from the previous question you submitted, try this:
          PIVOT Format(a.RegisteredDate,"yyyymmm");
0
 

Author Comment

by:WallyTee
ID: 24129869
Hi puppydogbuddy:   Thanks for the super-quick response!  

The Years and Months appeared OK, but they are in alphabetical and not chronological order, left to right.  I'd love to get them in chronological order.  Any ideas on this?
0
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 total points
ID: 24129948
No points for this, please :)

WallyTee said:
>>I'd love to get them in chronological order.  Any ideas on this?

PIVOT Format(a.RegisteredDate,"yyyy-mm")
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 24130013
Try this-change the two lines as indicated:
Year(Format(a.RegisteredDate, "yyyymmm")>2005      '<<<<<<<<
GROUP BY a.Product
PIVOT (a.RegisteredDate);                   '<<<<<<<<<<
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 24130020
oops, left out a right parens:

Year(Format(a.RegisteredDate, "yyyymmm"))>2005      
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24130057
Pivot Year(Format(a.RegisteredDate" "yyyy mmm") in ("Jan","Feb","Mar",.....,"Nov","Dec")
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24130061
Correction:

Pivot Format(a.RegisteredDate, "yyyy mmm") in ("Jan","Feb","Mar",.....,"Nov","Dec")
0
 
LVL 44

Expert Comment

by:GRayL
ID: 24130083
If you can accept 20008 11, 2008 12, 2009 01, etc>

PIVOT Format(a.RegisteredDate,"yyyy mm")


0
 

Author Closing Comment

by:WallyTee
ID: 31569497
Good solution. It uses numbers to represent months, but that's fine.  They appear in the correct order.  Many thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question