T-SQL Guru - Dynamic Pivot on Multiple Columns

Naomi N is our TechNet Guru for May! See more about the Technology Guru TechNet Wiki for May contest. 

She had two winning articles. Here is one:  T-SQL: Dynamic Pivot on Multiple Columns



And here's an excerpt from the article:

The problem of transposing rows into columns is one of the most common problems discussed in Transact-SQL forum. Many times the problem of creating a dynamic pivot comes into the light. One thing that many people who ask this question forget is that such transposing is much easier to perform on the client side than on the server where we need to resort to dynamic query. However, if we want to make such pivot dynamically, the important thing to understand is that writing dynamic query is only slightly more difficult than writing static query. In fact, when I am presented with the problem of dynamic pivot, I first figure out how static query should look like. Then making such query dynamically becomes rather trivial task.


Read the rest here:

T-SQL: Dynamic Pivot on Multiple Columns


Thanks to Naomi for all your great contributions to the TechNet Guru contest!

- User Ed