declare @columns varchar(max)
declare @convert varchar(max)
select @columns = stuff(( select '],[' + username
from TableName
order by '],[' + convert(varchar(max), points) desc
for xml path('')), 1, 2, '') + ']'
set @convert =
'select * from (select * from TableName) Tbl
pivot(sum(points) for username
in ('+@columns+')) as pivottable'
execute (@convert)This SQL Script helps you to convert Table rows into column
