question

KP3883 avatar image
KP3883 asked

Transpose 1 row

![alt text][1] [1]: /storage/temp/1318-untitled.png
sqlcountrow
untitled.png (5.3 KiB)
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Grant Fritchey avatar image Grant Fritchey ♦♦ commented ·
This site runs off of votes. Please mark all helpful answers by clicking on the thumbs up next to those answers. If any one answer lead to a solution, please indicate that by clicking on the check mark next to that answer.
0 Likes 0 ·
Venkataraman avatar image
Venkataraman answered
SELECT sap,[Enrollment Effective] as EnrollmentEffective, [Enrollment Signature] As EnrollmentSignature FROM (select SAP, eventtype, expr1002 from test) as a pivot ( min(expr1002) for eventtype in ([Enrollment Effective], [Enrollment signature])) as p
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Phil Factor avatar image
Phil Factor answered
There is a simple way of doing this. In this example I've embedded your test data in the solution for convenience Select sap, sum(case when eventtype='Enrollment Effective' then Expr1002 else 0 end) as [EnrollmentEffective], sum(case when eventtype='Enrollment Signature' then Expr1002 else 0 end) as [EnrollmentSignature] from (values (0, 'Enrollment Effective', 1), (0, 'Enrollment Signature', 1), (1, 'Enrollment Effective', 2), (1, 'Enrollment Signature', 2)) data(sap,eventtype,Expr1002) group by sap Or another alternate way of demonstrating this is ... declare @data table (sap int, EventType varchar(80), Expr1002 int) insert into @data (sap,eventtype,Expr1002) values (0, 'Enrollment Effective', 1), (0, 'Enrollment Signature', 1), (1, 'Enrollment Effective', 2), (1, 'Enrollment Signature', 2) Select sap, sum(case when eventtype='Enrollment Effective' then Expr1002 else 0 end) as [EnrollmentEffective], sum(case when eventtype='Enrollment Signature' then Expr1002 else 0 end) as [EnrollmentSignature] from @data d group by sap
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.