Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Tuesday, September 20, 2011

Pivot 3 Column in a table Sql Server

1: Table Structure

 2: Code 



SELECT ExhibitorID,
sum(CASE WHEN Installment ='Installment1'  THEN ReceivedAmount ELSE 0 END) AS Installment1,
max(CASE WHEN Installment ='Installment1' THEN ChequeDetails ELSE '' END) AS ChequeDetails1,

sum(CASE WHEN Installment ='Installment2'  THEN ReceivedAmount ELSE 0 END) AS Installment2,
max(CASE WHEN Installment ='Installment2' THEN ChequeDetails ELSE '' END) AS ChequeDetails2,

sum(CASE WHEN Installment ='Installment3'  THEN ReceivedAmount ELSE 0 END) AS Installment3,
max(CASE WHEN Installment ='Installment3' THEN ChequeDetails ELSE '' END) AS ChequeDetails3,

sum(CASE WHEN Installment ='Installment4'  THEN ReceivedAmount ELSE 0 END) AS Installment4,
max(CASE WHEN Installment ='Installment4' THEN ChequeDetails ELSE '' END) AS ChequeDetails4,

sum(CASE WHEN Installment ='Installment5'  THEN ReceivedAmount ELSE 0 END) AS Installment5,
max(CASE WHEN Installment ='Installment5' THEN ChequeDetails ELSE '' END) AS ChequeDetails5

FROM View_Test
GROUP BY ExhibitorID;


3: Out Put


































No comments:

Post a Comment