sencillo:
Código SQL:
Ver originalCREATE TABLE #temp
(
num INT,
clase01 BIGINT,
clase02 INT,
clase03 INT,
clase04 INT,
clase05 INT,
clase06 INT,
clase07 SMALLINT
)
INSERT INTO #temp VALUES (1 , 1000 , 2000 , 3000 , 4000 , 5000 , 6000,45)
INSERT INTO #temp VALUES (2 , 7000 , 8000 , 9000 , 10000 , 11000 , 12000,55)
SELECT tabla1.numero,tabla1.[1],tabla2.[2] FROM(
SELECT numero,[1]
FROM
(
SELECT CONVERT(BIGINT,clase01) AS clase01,CONVERT(BIGINT,clase02) AS clase02,
CONVERT(BIGINT,clase03) AS clase03,CONVERT(BIGINT,clase04) AS clase04,
CONVERT(BIGINT,clase05) AS clase05,CONVERT(BIGINT,clase06) AS clase06,CONVERT(BIGINT,clase07) AS clase07
FROM #temp WHERE num=1
) AS t1
unpivot
(
[1] FOR numero IN (clase01,clase02,clase03,clase04,clase05,clase06,clase07)
) AS t2
) AS tabla1
LEFT JOIN
(
SELECT numero,[2]
FROM
(
SELECT CONVERT(BIGINT,clase01) AS clase01,CONVERT(BIGINT,clase02) AS clase02,
CONVERT(BIGINT,clase03) AS clase03,CONVERT(BIGINT,clase04) AS clase04,
CONVERT(BIGINT,clase05) AS clase05,CONVERT(BIGINT,clase06) AS clase06,CONVERT(BIGINT,clase07) AS clase07
FROM #temp WHERE num=2
) AS t1
unpivot
(
[2] FOR numero IN (clase01 ,clase02,clase03,clase04,clase05,clase06,clase07)
) AS t2) AS tabla2 ON (tabla1.numero=tabla2.numero)
saludos!