this is my result set of sql query.
| Header | Mobile | EXE | Web | OverallOnline |
| % of Revenue contribution | 14.00 | 14.00 | 14.00 | 14.00 |
| % of your clients logging in | 14.00 | 14.00 | 14.00 | 14.00 |
| % of your clients Traded | 14.00 | 14.00 | 14.00 | 14.00 |
| National avg % of Revenue contribution | 14.00 | 14.00 | 14.00 | 14.00 |
How can i convert to
| For | % of Revenue contribution | % of your clients logging in | % of your clients Traded | National avg % of Revenue contribution |
| Mobile | ||||
| EXE | ||||
| Web | ||||
| OverallOnline |

Vinay SinghPosted Aug 31, 2016, 11:38 PM
DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)
select @cols = STUFF((SELECT ',' + QUOTENAME(ColumnName)
from yourtable
group by ColumnName, id
order by id
FOR XML PATH(''), TYPE
).value('.', 'NVARCHAR(MAX)')
,1,1,'')
set @query = 'SELECT ' + @cols + ' from
(
select value, ColumnName
from yourtable
) x
pivot
(
max(value)
for ColumnName in (' + @cols + ')
) p '
execute(@query)
Midhun TpPosted Aug 31, 2016, 1:45 AM