I have a function which produces 5 columns of results (and say for example, 10 rows).
This data is being inserted into a Key-Value table and so I need to get it into the format of the 50 rows for insertion.
At the moment I am currently selecting each column five times and union-ing the results together. As it is the same query being run five times, but only one column selected each time this seems very inefficient. Ideally I could only run the query once, but transpose the data from 5 x 10, to 1 x 50.
So if my query returns two rows of: [ID],[ColA],[ColB],[ColC],[ColD],[ColE]
I would like to get this into the format:
[ID0],[ColA0]
[ID0],[ColB0]
[ID0],[ColC0]
[ID0],[ColD0]
[ID0],[ColE0]
[ID1],[ColA1]
[ID1],[ColB1]
.
.
Just replace the CTE with your data and you should be good to go.