-- File Name: jagat_patel_tsqlchallenge_15.sql SELECT Row,[1],[2],[3],[4],[5],[6],[7],[8],[9] FROM ( SELECT r.Row,c.Col, CASE WHEN r.Row%c.Col = 0 THEN 'X' ELSE '' END AS Div FROM @Rows r CROSS APPLY @Cols c ) as p PIVOT ( MAX(div) FOR Col IN ( [1],[2],[3],[4],[5],[6],[7],[8],[9]) ) AS pvt ORDER BY pvt.Row;
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.