TSQL Challenge 15 - Solution by Tony Bater



-- File Name: tony_bater_tsqlchallenge_15.sql
select Row
, case when [1] = 1 then 'x' else '' end [1]
, case when [2] = 1 then 'x' else '' end [2]
, case when [3] = 1 then 'x' else '' end [3]
, case when [4] = 1 then 'x' else '' end [4]
, case when [5] = 1 then 'x' else '' end [5]
, case when [6] = 1 then 'x' else '' end [6]
, case when [7] = 1 then 'x' else '' end [7]
, case when [8] = 1 then 'x' else '' end [8]
, case when [9] = 1 then 'x' else '' end [9]
from (
select Row, [1], [2], [3], [4], [5], [6], [7], [8], [9]
from 
(
select Row, Col, Row%Col Modulus
from @Rows
cross join @Cols
where Row%Col=0
) as SourceTable
PIVOT
(
Count(Modulus)
for Col in ([1], [2], [3], [4], [5], [6], [7], [8], [9])
) as PivotTable
) Results




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.