I am trying to normalize a few tables. Here is one of my tables
SalesID|Order1Name|Order1Date|Order1Amt|Order2Name|Order2Date|Order2Amt|Order3Name......Order10xxxx
---------------------------------------------------------------------------
1001 | first | 1/1/18 | 111.00 | second | 2/1/18 | 222.00
I want to get it to
SalesID |OrderNum | OrderName | OrderDate | OrderAmt|
------------------------------------------------------------
1001 1 first 1/1/18 111.00
1001 2 second 2/1/18 222.00
1001 .
1001 .
1001 10
I have been trying to run with unpivot – how do make sure I have the ordinality (column2) info?
Best Answer
I started with the information in Aaron Bertrand's awesome post Use SQL Server's UNPIVOT operator to dynamically normalize output. You should read the information in that post as Aaron does a great job of explaining the process.
I had to make some changes to Aaron's process due the fact that you had more columns that what Aaron had in his example(s).