Transposing Data

Or, you can use the method @gbritton used in this post, like this:

CREATE TABLE #tmp 
	(col1 VARCHAR(32), col2 INT, col3 INT, col4 INT, col5 INT, col6 INT);
INSERT INTO #tmp VALUES 
	('CatA',10,2,5,15,16),
	('CatB',9,3,4,11,13), 
	('CatC',20,22,25,15,16);

SELECT
	c1.col1,c2.col2
FROM
	#tmp
	CROSS APPLY
	(
		VALUES(col1)
	) c1(col1)
	CROSS APPLY
	(
		VALUES (col2),(col3),(col4),(col5),(col6)
	) c2(col2);

DROP TABLE #tmp;
1 Like