SQL Server dynamic CTE combined with dynamic SQL execution

I am trying to build a CTE based reporting solution where the CTE serves as a variable source. I'm calling the CTE on the fly, and feeding it dynamic SQL in the form of an arbitrary number of columns that may or may not change. The data source will need to be concatenated together before the final SELECT so I need to account for unknown and variable number of columns.
Here 66cf4387b8 fairhel