Reputation: 15698
Here is a bit of background just in case there is a different/better way of solving my problem.
I have a query that I've exported from Access to a spreadsheet. The exported data was a pivot query export which I passed it off to another worker who has updated the table and passed it back to me. Also, the underlying data is actually a linked table from SQL 2005. I'm mentioning that because I'm not afraid to us SQL Server to update this data, but since the export originated from Access, I assumed it would be best to update it from their.
This is the basics of what the table data and export was structured like: I
Data Table
==========
PK_1 PK_2 VALUE
------------------------------
G1 SG1 .33
G1 SG2 .44
...
G2 SG1 .33
G2 SG2 .44
...
G3 SG1 .33
G3 SG2 .44
...
..and this is what the exported data looked like in Excel.
Pivot Data Exported to Excel
============================
G1 G2 ...
SG1 .33 .33 ...
SG2 .44 .44 ...
SG3 .55 .55 ...
... ... ... ...
My question is how can I unpivot the updated spreadsheet data into my data table that needs to be updated? Is there an unpivot operation in Access, possibly as part of an importation process?
Upvotes: 0
Views: 420
Reputation: 247720
MS Access does not have an UNPIVOT but you can do this via multiple UNION queries
http://www.access-programmers.co.uk/forums/showthread.php?t=204468
How to convert fields into rows through SQL in MS Access 2007 or MS SQL Server 2005
here is an example with your data:
SELECT PK_2, "G1" as "PK_1", G1 as [Value]
FROM Table
UNION
SELECT PK_2, "G2" as "PK_1", G2 as [Value]
FROM Table
Upvotes: 1