Solved

How to convert a crosstab type table to flat file format

Posted on 2000-03-07
5
1,602 Views
Last Modified: 2008-01-16
Imagine a table with 10 records with column headings as follows:-
Expense Type; Cost Centre; Week 1; Week 2; Week 3; Week 4; Week 5

Where Expense Type and Cost Centre is Narrative, and all other columns are values.

Is there a simple way to convert this to a more simplistic table with 50 records with column headings as:-
Expense Type; Cost Centre; Week No; Value

The requirement is effectively the inverse of a crosstab query,

Regards
0
Comment
Question by:AGD
  • 3
  • 2
5 Comments
 
LVL 9

Accepted Solution

by:
BrianWren earned 30 total points
ID: 2593694
SELECT [Expense Type], [Cost Centre], 1 As [Week No], [Week 1] As [Value]
FROM tbl

UNION ALL
SELECT [Expense Type], [Cost Centre], 2 As [Week No], [Week 2] As [Value]
FROM tbl

UNION ALL
SELECT [Expense Type], [Cost Centre], 3 As [Week No], [Week 3] As [Value]
FROM tbl

UNION ALL
SELECT [Expense Type], [Cost Centre], 4 As [Week No], [Week 4] As [Value]
FROM tbl

UNION ALL
SELECT [Expense Type], [Cost Centre], 5 As [Week No], [Week 5] As [Value]
FROM tbl;

Brian
0
 

Author Comment

by:AGD
ID: 2601785
Thanks - this opens up a whole load of options

Regards
0
 
LVL 9

Expert Comment

by:BrianWren
ID: 2601824
I just learned about UNION queries last week...  Glad to help.
0
 

Author Comment

by:AGD
ID: 2602427
I noticed you'd posted a question after I'd written mine re UNION generally !!

Suppose my question accidentally gave an answer to yours !

Regards

Andrew
0
 
LVL 9

Expert Comment

by:BrianWren
ID: 2602469
Well, these unions had seemed an odd creature to me, and are infrequently encountered, (or mentioned in manuals, etc.)

So I posted my question to bring answers out of the woodwork.  But they still seemed a bit useless.  Till I saw your question, and realized that a bunch of passes through the records would really hit the spot.

Answering your question is the first use that I've had from the question that I had posted.

Brian
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

932 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now