SELECT Name1, Name2, Value FROM mytable gives me the following result set:
Name1 Name2 Value A P1 1 A P2 1 A P3 2 B P1 3 B P2 1 B P4 1
How do I translate that to:
A B
P1 1 4
P2 1 1
P3 2 null
P4 null 1
Thanks,
You can use a PIVOT clause. Your query could be something like this:
using your sample data above, my results were
EDIT:
Since you have an unknown number of columns, you will need to look at using dynamic SQL and there are several answers here on SO about that with PIVOT.
SQL Server 2005 Pivot on Unknown Number of Columns
Pivot Table and Concatenate Columns