Solved

How to convert a crosstab type table to flat file format

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

831 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