Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
follwing is the table
--------------------------------------
id | num |val
1 | num1 |val1
2 | num1 |val2
3 | num1 |val3
4 | num1 |val4
5 | num1 |val5


And I wanted to display link this

num1 | val1|val2|val3|val4|val5
How can I achieve this?
Posted

1 solution

Have a look here:
Script to create dynamic PIVOT queries in SQL Server[^]
Pivoting the Dynamic Way[^]
Pivots with Dynamic Columns in SQL Server 2005[^]

Static form of pivot:
SQL
SELECT num, [val1], [val2], [val3], [val4], [val5]
FROM (
    SELECT num, val
    FROM TableName
) AS DT
PIVOT (MAX(val) FOR num IN([val1], [val2], [val3], [val4], [val5])) AS PT
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900