• ajames 36824 (2/22/2013)


    Jeff Moden (2/22/2013)


    ajames 36824 (2/22/2013)


    You ROCK! 😀

    Do you understand how and why it works?

    Well it looks like it says that for each question in the QuestionID column, return the maximum numerical value related for the associated Response and making the rest blank. In order to do this, Response must be converted to characters. The Group By statement pivots all the other variables not in the statement and groups them based on those variables. Is that right?

    Not sure I'd say it quite like that.

    The GROUP BY collapses all rows where the value of the grouped columns is the same, thus the rest of the columns are free to be pivoted. Which is done by one MAX/CASE per column to be pivoted.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St