473,379 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Ms Access Help with Union & transposing data

Hi Guys,

I am a newbee to Bytes currently working on an MS Access database for one of my clients:

With respect, I'll get right to it:

I have 2 tables:
Table 1. TblTrip_Facts
Route Name , FactTypeId ,CustomerName ,RouteType
AISX1-0103 , 0 , TTMA , DEDICATED
AISX1-0104 , 0 , TTMA , DEDICATED


Table 2: TblLabel
Labels,
RouteType,
CustomerName,
Route Name,


I am looking to export a CSV file that looks like the following:

FINAL OUTPUT: My wish list. (TABLE B)

TripReference, FactTypeID, Label, Value
AISX1-0103, 0, RouteType , DEDICATED
AISX1-0103, 0, CustomerName, TTMA Tetsu Group
AISX1-0103, 0, Route Name, AISX1-0103
AISX1-0104, 0, RouteType , DEDICATED
AISX1-0104, 0, CustomerName, TTMA Tetsu Group
AISX1-0104, 0, Route Name, AISX1-0104

Please let me know if you have any ideas on how I can convert my tables to one table (TABLE B) and include a new field Value.

Thanks for the help in advance.
Nov 3 '09 #1
7 2758
NeoPa
32,556 Expert Mod 16PB
The information you give is quite clear as far as it goes, but you haven't given any linking information. What relationship do the tables bear to each other?

Another problem is that you seem to want the fields renamed for use in your new table, yet you haven't explained this. Most of us are intelligent enough to work it out for ourselves eventually, but few of us appreciate having to ;)
Nov 3 '09 #2
Neopa: thank you for the response.

Part 1 of your question:

This is how the tables are associated.

The Row headings (RouteFacts, Route Name, CustomerName) in Table 1tbl_TripFacts are values in Table 2 TblLabel under the Label Feild

Basically: Table1's field names have been transposed to form Table 2's data under the field name "Labels".

Part 2:

Good obsavation. My mistake. The field Routes will be renamed to TripReference (I can handle that renaming)

In Detail: For every TripReference There is a RouteType, CustomerName and a Route Name. I want these to show up under the field name "Value" reading from top to bottom with TripReference being repeated as opposed to from left to right.
Nov 3 '09 #3
NeoPa
32,556 Expert Mod 16PB
I'm trying to work out what you mean, but you've introduced more new problems with your explanation than you explain.

Could you try this again, but be very careful to get all the details correct. Where something differs from what you've said before then you need to point this out otherwise I have no way of knowing which version you made the mistake on. I cannot work with this as it stands, as it is too unclear. Far too much would be guesswork.

You've clearly put effort into getting this right, but it seems you still need a little guidance to see the most important parts.

The importance is in the detail. If you learn nothing more about database work than this point you will still have made much progress.
Nov 3 '09 #4
Let me try this one more time:

Table 1. contains the Trip facts

Table 2. Contains the specific trip details

My Questions:

1. How I can combine data from two fields and stack it up in a single collumn
2. How can I use one tables field headings as data in another table
In Ms excel it would be a cut and paste then transpose.
Nov 4 '09 #5
NeoPa
32,556 Expert Mod 16PB
I'm sorry.

I cannot for the life of me see why posting this question should be as complicated as it seems to be for you. I thought I was being clear in my explanation of why I cannot work with this. Perhaps I wasn't clear enough. I really cannot think what I can say more than I have already. I certainly haven't got the time to weave through all the various posts trying to put something together that may make sense. This is your responsibility of course. So far all we have (as far as I can see) is a few posts with bits of the puzzle in them. Unfortunately, as some of the say different things from the others, it's not even as simple as just putting them together. I still need to know which information is reliable.

I think we'd better just call it a day to be honest. Such a shame, as I thought your first post indicated such promise.
Nov 8 '09 #6
Thanks NeoPa:

This worked incase anyone runs into the same issue.
Expand|Select|Wrap|Line Numbers
  1. SELECT TripReference, FactTypeID, 'RouteType' AS Label, RouteType AS [Value] FROM [CM Trips]
  2. UNION
  3. SELECT TripReference, FactTypeID, 'CustomerName' AS Label, CustomerName AS [Value] FROM [CM Trips]
  4. UNION
  5. SELECT TripReference, FactTypeID, 'RouteName' AS Label, [Route Name] AS [Value] FROM [CM Trips];
Nov 8 '09 #7
NeoPa
32,556 Expert Mod 16PB
Ironically, it now seems clear what you were trying to ask for.

Just a couple of tips I can add :
  1. In a UNION query, the names of the fields are only important in the first line. I sometimes use them anyway, for clarity, but it's worth noting. In fact I would recommend you do, but only if you can always rely on yourself getting them correct 100%. Otherwise it can be misleading.
  2. In case it helps, you can sort the results of a UNION query, although not within each query.
My recommendation then, would be :
Expand|Select|Wrap|Line Numbers
  1. SELECT   TripReference,
  2.          FactTypeID,
  3.          'RouteType' AS [Label],
  4.          RouteType AS [Value]
  5. FROM     [CM Trips]
  6. UNION
  7. SELECT   TripReference,
  8.          FactTypeID,
  9.          'CustomerName' AS [Label],
  10.          CustomerName AS [Value]
  11. FROM     [CM Trips]
  12. UNION
  13. SELECT   TripReference,
  14.          FactTypeID,
  15.          'RouteName' AS [Label],
  16.          [Route Name] AS [Value]
  17. FROM     [CM Trips]
  18. ORDER BY TripReference,
  19.          FactTypeID,
  20.          [Label]
You may choose a different order, but you can see what I mean.
Nov 8 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: CJM | last post by:
I have a query which produces different results in the Access query builder and in an ASP page (via ADO) An example of the query is: ----------------------------------------------------------...
0
by: s_gregory | last post by:
The mdb is considerable size 70 +- mb. A complex union query was working well, but when an additional union select... was added into the query, selecting identical fields from a different source,...
0
by: jwa6 | last post by:
We have recently went to access 2003 from access 97. And from word 97 to Word 2003. We have an Access application we use for ms word mail mergers to a 5160 mail label format. The data for the...
3
by: Dan | last post by:
I hate it when people think that their own misunderstandings are bugs in the program, but this time I think I've got something. If I run the following SQL code in Access 2000, I get unexpected...
0
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank...
2
by: marco | last post by:
Dear List, as it seems, MS SQL as used in Access does not allow a select INTO within a UNION query. Also, it seems that a UNION query can not be used as a subquery. Maybe my (simplified)...
9
by: Classic-Car-World Ltd | last post by:
Hi, I have some data in a table in columns which I need to convert into rows. This is specification data for some tools etc. The data is currently in the following format: Product No, order,...
1
by: smaczylo | last post by:
Hello, I've recently been asked to work with Microsoft Access, and while I feel quite comfortable with Excel, I'm at a complete loss with databases. If someone could help me with this issue I'm...
8
by: RJMac | last post by:
I’m using ADO 2.6 in VB6 to read in data from a Union query (qryJoinBalanceData) in Access 2000. The Union query contains 3 sub-queries, each of which joins several tables, but they all generate...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.