-- File Name: bret_warnick_tsqlchallenge_15.sql
select row as col /*to get the wanted output alias this as col*/
, [1], [2], [3], [4], [5], [6], [7], [8], [9]
from
/*For the main part of the query, cross join the two
tables and place an x on those where row mod col=0*/
(select r.row, c.col,
case when r.Row % c.col =0 then 'x' else '' end Divisible
from @Rows r cross join @Cols c) s
PIVOT
(
min(Divisible) /*There's really only one possibility here, but this needs to be an aggregate*/
FOR col IN
( [1], [2], [3], [4], [5], [6], [7], [8], [9] )
) AS pvt
ORDER BY 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.