Advertisement

01.13.2008 at 07:46PM PST, ID: 23079957
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.6

is it possible to order columns generated by a crosstab query using another query?

Asked by rsmuckles in Microsoft Access Database, SQL Query Syntax

Tags: , , ,

I have a crosstab query (code below) that does the following -

matches item & price data or different restaurants from a table called temp_all_items

with a description of the financial quarter in which it was collected (from dim)

and the city name associated with its location ID (from location)

The resulting datasheet "stacks" the location and quarter data so that Q107 Chicago data is all under a column called Q107 CHI, and so on.  The problem is that the columns generated (quarter & location) are not in chronological order, so Q308 ATL might come before Q106 NYC.  The columns need to be shown in chronological order by financial quarter and then in alphabetical order by location.

I'm unable to figure out how to either make the crosstab query show the columns in the order I'd like.  I have a query which has all of the possible column names that could be generated, in the order they should be displayed, and thought that maybe I could use it create another query which took the results in order, but I'm unable to wrap my mind around how I might begin.  The query, location_qtr, looks like this:

Expr1      location_id      city      ID      description
Q105 Atl      81      Atlanta      63      Q105
Q105 Atl      11      Atlanta      63      Q105
Q105 Atl      71      Atlanta      63      Q105
Q105 Atl      16      Atlanta      63      Q105
Q105 Atl      66      Atlanta      63      Q105
Q105 Atl      46      Atlanta      63      Q105
Q105 Atl      61      Atlanta      63      Q105
Q105 Atl      76      Atlanta      63      Q105
Q105 Atl      31      Atlanta      63      Q105
Q105 Atl      21      Atlanta      63      Q105
Q105 Atl      56      Atlanta      63      Q105
Q105 Atl      41      Atlanta      63      Q105
Q105 Atl      1      Atlanta      63      Q105
Q105 Atl      86      Atlanta      63      Q105
Q105 Atl      51      Atlanta      63      Q105
Q105 Atl      36      Atlanta      63      Q105
Q105 Atl      6      Atlanta      63      Q105
Q205 Atl      46      Atlanta      64      Q205
Q205 Atl      11      Atlanta      64      Q205
Q205 Atl      71      Atlanta      64      Q205
Q205 Atl      16      Atlanta      64      Q205
Q205 Atl      66      Atlanta      64      Q205
Q205 Atl      21      Atlanta      64      Q205
Q205 Atl      61      Atlanta      64      Q205
Q205 Atl      86      Atlanta      64      Q205
 . . . you get the picture.

Has anyone done this kind of thing before?Start Free Trial
1:
2:
3:
4:
5:
6:
TRANSFORM First(temp_all_items.price) AS FirstOfprice
SELECT temp_all_items.chain_name AS Chain, IIf([new_flag]<>0,'New','') & IIf([deleted_flag]<>0,'Deleted','') & IIf([back_flag]<>0,'Back','') AS Notes, temp_all_items.category_name AS Category, temp_all_items.item_name AS Item
FROM (temp_all_items LEFT JOIN dim ON temp_all_items.qtr_id = dim.ID) INNER JOIN location ON temp_all_items.location_id = location.location_id
GROUP BY temp_all_items.chain_name, IIf([new_flag]<>0,'New','') & IIf([deleted_flag]<>0,'Deleted','') & IIf([back_flag]<>0,'Back',''), temp_all_items.category_name, temp_all_items.item_id, temp_all_items.item_name
ORDER BY temp_all_items.chain_name, temp_all_items.category_name, temp_all_items.item_name, temp_all_items.item_id, temp_all_items.chain_name
PIVOT [dim]![description] & " " & Left([location]![city],3);
[+][-]01.13.2008 at 08:42PM PST, ID: 20650919

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.13.2008 at 09:05PM PST, ID: 20651010

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01.13.2008 at 09:36PM PST, ID: 20651108

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Access Database, SQL Query Syntax
Tags: Microsoft, Access, 2007, crosstab query column order
Sign Up Now!
Solution Provided By: puppydogbuddy
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628