Friday, 7 October 2016

Convert Rows to columns using 'Pivot' in SQL Server

Convert Rows to columns using 'Pivot' in SQL Server

Description:

In this example we explain that how to covert rows to column and column to rows in SQL Server.SQL Query to convert row data to column in SQL Server.sql query to display row data to column.or convert rows to columns using Pivot in SQL Server when columns are string data type.

Here we demonstrate switching rows and column in SQL Server. Or convert rows values into column value in SQL Server. Display row value in column value in SQL Server.
Query:-


SELECT empid ,Name, [Basic], [TA],[DA]
FROM (
SELECT empid, wage, amount,Name
FROM Demo) up
PIVOT (SUM(amount) FOR wage IN (basic, ta,da)) AS pvt
ORDER BY empid,Name
GO


This entry was posted in :

0 comments:

Post a Comment