How to do the row to column SUMIF in MS SQL Server

sql-server

Solution

You can try like this..

Select Person,
           Sum(Part)as Part,
           Sum(Case when Status='A' then 1 End) AS Status-A,
           Sum(Case when Status='B' then 1 End) AS Status-B,
           Sum(Case when Status='C' then 1 End) AS Status-C 
           from Table-A
           Group By Person;

Problem

Suppose I have a table called "TABLE-A", I would like to do the SUMIFS like the image For the total I could do it by `SUM` and `GROUP BY` but to have the columns lay-out like the one I would like to have I could not do it In addition, I would like to know if this is doable that because there might be new statuses as database grows, is there anyway to make the column header to be item in Status? Thanks

Original source