Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

Spalte zu Zeile in SQL Server?

Sie können den UNPIVOT verwenden Operation, um Ihre Ergebnisse zu erhalten

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;