Dynamic PIVOT statement

My attempt to make a dynamic PIVOT statement. The table used is the same as the example in my 70-761 book.

First, theĀ @list_of_columns parameter is filled to create a list of columns, using COALESCE. Next a common table expression is used. In this example. it is not useful, but as more complicated PIVOT statements will usually work with tables with more than the required 3 columns, I left this cte in there.

Add a second @list_of_columns parameter to replace the NULL values in the result set.





This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *