I've looked at a number of SQL transpose threads here and all of them deal with restructuring data and/or data summaries. I have a somewhat common situation that doesn't match any of those circumstances. Please keep in mind this is in MS Access, and using a linked table (so, no updating permitted and there's no key or id).
I have the linked table. There are only two long rows of data. Say, it's a listing of unique Business Units (BUs) and corresponding annual sales.
linked_table
F1 F2 F3 F4 F5 ...
-----------------------------
row1 BU11 BU123 BU223 BU2 BU432...
row2 $2345 $0 $50.50 $234 $567.22
I need this data set transposed somehow into this:
new_table or new_query
BU Sales
---------------
BU11 $2345
BU123 $0
BU223 $50.50
BU2 $234
BU342 $567.22
...
Again, there are only two long rows of data in a linked Access table. I've only found a very tedious and ugly way to do about this, and was wondering if there's a better way to do this.
STEP 1 I've separated the two rows of data into 2 separate queries
headers_qry
F1 F2 F3 F4 F5...
------------------------------
row1 BU11 BU123 BU223 BU2 BU432...
data_qry
F1 F2 F3 F4 F5...
------------------------------
row1 $2345 $0 $50.50 $234 $567.22...
Then I've hardcoded a dummy "common key" into both data sets
headers_qry
F1 F2 F3 F4 F5... KEY
----------------------------------------------
row1 BU11 BU123 BU223 BU2 BU432... UNIQUE123
data_qry
F1 F2 F3 F4 F5... KEY
-----------------------------------------------
row1 $2345 $0 $50.50 $234 $567.22... UNIQUE123
Then I've added a join on between the two queries on that common key and manually paired up Header and Data pairs through hundreds of UNION statements. Ouch!!!!
SELECT
headers.F1 AS BU_Number,
data.F1 AS BU_Sales
FROM header_data_join_qry UNION ALL
SELECT
headers.F2 AS BU_Number,
data.F2 AS BU_Sales
FROM header_data_join_qry UNION ALL
SELECT
...
headers.F100 AS BU_Number,
data.F100 AS BU_Sales
FROM header_data_join_qry UNION ALL;
Not only is this tedious and ugly, MS ACCESS can't handle these multiple UNION ALL queries and once I've reached around 100 it started giving the SQL statement too complex error.
Is there a way to handle this better, considering limitations of the linked source table and the MS ACCESS SQL environment? Thanks so much!