Unfortunately not, except for stored procedures. SQL Server monitors the definition of the output table for all views, functions, etc. Thus, columns and types cannot dynamically change at the input.
For this reason, I have never found the PIVOT operator useful. Generally, the only way to get variable column data is to treat it as XML.
For what reason are you turning it? This is usually a problem with the user interface, so I would recommend doing this in the user interface or SSRS, etc.
Joel mansford
source share