TSQL Challenge 15 - Solution by Andrew Hogg



-- File Name: andrew_hogg_tsqlchallenge_15.sql
Select row as col,[1],[2],[3],[4],[5],[6],[7],[8],[9]

From
(
	Select col, row, (case (row % col) when 0 then 'x' else '' end) as divis  
	From @cols C join @rows R on 1=1
) p
Pivot
(
	Max(divis)
	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.