TSQL Challenge 15 - Solution by Leonid Koyfman (2)



-- File Name: leonid_koyfman_tsqlchallenge_15_2.sql
------------------------------------- S O L U T I O N  #2  ----------
SELECT 
	Col=Row
,	[1]=ISNULL(CHAR([1]),'')
,	[2]=ISNULL(CHAR([2]),'') 
,	[3]=ISNULL(CHAR([3]),'') 
,	[4]=ISNULL(CHAR([4]),'') 
,	[5]=ISNULL(CHAR([5]),'') 
,	[6]=ISNULL(CHAR([6]),'')  
,	[7]=ISNULL(CHAR([7]),'')  
,	[8]=ISNULL(CHAR([8]),'')  
,	[9]=ISNULL(CHAR([9]),'')  
FROM
(	SELECT	
		Col
	,	Row
	,	X=88--ASCII code for Character X
	FROM 
		@Cols c INNER JOIN 
		@Rows r ON r.Row%c.Col=0
)AS T
PIVOT 
(
	MAX(X) FOR Col IN([1],[2],[3],[4],[5],[6],[7],[8],[9])
)AS P;

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.