I receive a denormalized text file that must be loaded into a normalized table.
Denormalized table:
CustomerID — Category — Category2 — Category3 — Category4
1 — A — B — C — D
When this is normalized, it should look like:
CustomerID — Category
1 — A
1 — B
1 — C
1 — D
What is the best way to write a T-SQL statement to achieve this (SQL Server 2008)?
Use the
UNPIVOTkeyword: http://technet.microsoft.com/en-us/library/ms177410.aspxNaturally you’ll want to replace [File] with some sort of OpenRowSet query or use the import/export wizard to get the data into a temp table.