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

 

Comments (7)

  1. Naomi Nosonovsky says:

    This article has been useful in a recent thread social.technet.microsoft.com/…/help-with-a-query

  2. User Ed says:

    Nice! It goes from Forum to Wiki and then back to Forums! This is great!

  3. Kamlakar Singh says:

    I will present how we can write a Dynamic PIVOT query with an example, where we don’t need to mention the PIVOT columns each unique values.

    Pivot is one the new relational operator introduced in SQL Server 2005. It provides easy mechanisms in SQL Server to transform rows into columns.

    for full implementation of Pivot with Dynamic columns check here:

    <a href="http://www.mindstick.com/…/Pivot%20with%20Dynamic%20columns%20in%20SQL%20Server&quot; target="_blank">Pivot with Dynamic columns in SQL Server</a>

  4. kamlakar singh says:

    I will present how we can write a Dynamic PIVOT query with an example, where we don’t need to mention the PIVOT columns each unique values.

    Pivot is one the new relational operator introduced in SQL Server 2005. It provides easy mechanisms in SQL Server to transform rows into columns.

    for full implementation of Pivot with Dynamic columns check here: http://www.mindstick.com/…/Pivot%20with%20Dynamic%20columns%20in%20SQL%20Server

  5. User Ed says:

    Thanks Kamlakar! You can also post this as an article on TechNet Wiki!

  6. User Ed says:

    Computers Today (part 1 of 6)

    blogs.msdn.com/…/computers-today.aspx

    …..

    CS SPOTLIGHT: Girls in computer programming… why it matters!!!

    blogs.msdn.com/…/cs-spotlight-girls-in-computer-programming-why-it-matters.aspx

    Computational Thinking – Videos & Papers by Jeannette Wing

    blogs.msdn.com/…/computational-thinking-videos-amp-papers-by-jeannette-wing.aspx