ajames 36824 (2/22/2013) Jeff Moden (2/22/2013)
ajames 36824 (2/22/2013)
You ROCK! :-D
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?
Mostly correct. I say "mostly" because you don't actually need to convert the respose to VARCHAR. Dwaine did that just so he could show a blank instead of a NULL (which also suppresses the NULL aggregate warning messages).
If you'd like to do a deeper dive on CrossTabs and Pivots, here are a couple of articles that start you on the ground floor and move you all the way through dynamic CrossTabs.http://www.sqlservercentral.com/articles/T-SQL/63681/http://www.sqlservercentral.com/articles/Crosstab/65048/
is pronounced ree-bar and is a Modenism for R
First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
Although they tell us that they want it real bad, our primary goal is to ensure that we dont actually give it to them that way.
Although change is inevitable, change for the better is not.
Just because you can do something in PowerShell, doesnt mean you should. Helpful Links:
How to post code problemsHow to post performance problemsForum FAQs