Convert sql Rows into Column using Pivot as shown below

65 views Asked by At

I am looking to generate a report which is basically a attendance report using SQL query from table data rows; I have employee punch data as row in table with columns such as PDate | EmpCode | EmpName | PStatus | OT enter image description here

The above image shows the snap of data in table.

I am looking to generate the results as shown below enter image description here

1

There are 1 answers

0
Narendra Modi On
SELECT * FROM ( SELECT [Name], [Value] FROM [dbo].[Table] ) AS SourceTable PIVOT ( MAX([Value]) FOR [Name] IN ( [FirstName], [LastName], [Email], [Phone] ) ) AS PivotTable

I hope it will help you.