Jared Westover performs a technique showdown:
A few weeks ago, I helped someone combine multiple integer columns into a single column. The common term for this process is unpivoting or transposing. The table they worked with had millions of rows, so they needed the most efficient method to accomplish this task. If you search online, you’ll find several suggestions for doing this. But which performs best? Is one easier to maintain than the others?
Click through for a review of three separate techniques: using the UNPIVOT
operator, using UNION ALL
, and using CROSS APPLY
. The dataset was relatively small, but even at that size, CROSS APPLY
did a good job. But I won’t spoil too much here.