Declare @paramList VARCHAR(MAX) SET @paramList = STUFF(( SELECT DISTINCT ',[' + Question + ']' FROM View_S FOR XML PATH('') ) ,1,1,'') Print @paramList DECLARE @query NVARCHAR(MAX) SET @query = 'SELECT RollNo,SName,'; + @paramList + 'FROM( SELECT RollNo,SName,Results,Question FROM View_S )src PIVOT(Max(Results) FOR Question IN (' + @paramList +')) pvt' EXEC sp_executesql @query
Declare @paramList VARCHAR(MAX) SET @paramList = STUFF(( SELECT DISTINCT '],[' + Question FROM View_S ORDER BY '],[' + Question FOR XML PATH('')) ,1,2,'') + ']' PRINT @paramList
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)