Crag is right, you have the PIVOT feature in SQL Server - and for that matter, SSRS has dynamic pivot capabilities. Not every app can take advantage of this, but you can have an SSRS report that uses a dynamic pivot/matrix, and programmatically redirect the output to another destination. So there are multiple ways to solve it - I wouldn't think it would be necessary to have to involve C# code.