Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

da colonna a riga nel server sql?

Puoi usare il UNPIVOT operazione per ottenere i tuoi risultati

SELECT col, value
FROM 
   (SELECT CAST(col1 AS VARCHAR) AS col1, CAST(col2 AS VARCHAR) AS col2,
        CAST(col3 AS VARCHAR) AS col3, CAST(col4 AS VARCHAR) AS col4
   FROM Table1) p
UNPIVOT
   (value FOR col IN 
      (col1, col2, col3, col4)
) AS unpvt;