Solved

How to convert a crosstab type table to flat file format

Posted on 2000-03-07
5
1,581 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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

747 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

11 Experts available now in Live!

Get 1:1 Help Now