Solved

How to convert a crosstab type table to flat file format

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

726 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