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
Solved

How to convert a crosstab type table to flat file format

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
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 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…
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…

828 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