TSQL Challenge 15 - Solution by Dalibor Margotic



-- File Name: Dalibor_Margotic_tsqlchallenge_15.sql
SELECT *
FROM
(
	SELECT COLS.Col AS Col, ROW.Row AS Row, CONVERT(CHAR(1),CASE Row.Row % COLS.Col WHEN 0 THEN 'x' ELSE '' END) AS Result
	FROM @cols AS COLS
	CROSS JOIN @Rows AS ROW
) AS REC
PIVOT (MAX(Result) For Col in ([1],[2],[3],[4],[5],[6],[7],[8],[9])) AS 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.