-- File Name: rob_farley_tsqlchallenge_15_2.sql /* Second option, using an INNER JOIN */ WITH Xs AS ( SELECT *, 'X' AS X FROM @Cols c JOIN @Rows r ON r.row % c.col = 0 ) SELECT Row, ISNULL([1],'') AS [1], ISNULL([2],'') AS [2], ISNULL([3],'') AS [3], ISNULL([4],'') AS [4], ISNULL([5],'') AS [5], ISNULL([6],'') AS [6], ISNULL([7],'') AS [7], ISNULL([8],'') AS [8], ISNULL([9],'') AS [9] FROM Xs PIVOT (MAX(X) FOR Col IN ([1],[2],[3],[4],[5],[6],[7],[8],[9])) pvt ;
Did you find something incorrect/wrong with this solution? Take a few seconds to Report It.
Did you understand how this solution work? If you find it difficult to understand, you can Request an Explanation or you can Write an explanation to help others better understand this solution.