troubleshooting Question

Pivot SQL Query

Avatar of rwheeler23
rwheeler23Flag for United States of America asked on
Microsoft SQL Server
8 Comments1 Solution296 ViewsLast Modified:
This query list each contributor by year. What I would like is to see

Contributor   Year 1  Year 2  Year 3 Year 4

For example:
Contributor   Year 1  Year 2  Year 3 Year 4
100                 $100      $200   $300  $400
200                   $50      $100   $150  $200

SELECT year( as YearContrib,t2.MemberNumberId,sum(coalesce([Amount],0)) as Amount
FROM [Contribution Details] t1
inner join [Contribution Headers] t2 on t1.ContribHeaderId=t2.ContribNumberId
group by t2.MemberNumberId,year(      
order by MemberNumberId,year(

How do I restructure this query to accomplish this? I am using SQL Server 2012
Surendra Nath
Technology Lead

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros