I have read many question on Stack Overflow related to my problem, but I don\'t think they quite address my problem. Basically I download a XML dataset with lots of data, and in
SELECT NameID , [AA] as AA,[BB] as BB,[CC] as CC,[DD] as DD
FROM
(
SELECT Name,Data,NameID FROM Table1
)PivotData
PIVOT
(
max(Data) for Name in ([AA],[BB],[CC],[DD])
) AS Pivoting