SQLTeam.com | Weblogs | Forums

Pivot data

I need to pivot the following table as follows

Id,num1,num2,num3,num4,num5
1,null,null,3,null,null
1,5,null,null,null,null
1,null,6,null,null,null
1,null,null,null,null,9

Pivot to a single row

Id,num1,num2,num3,num4,num5
1,5,6,3,null,9

SELECT Id,
    MAX(num1) AS num1,
    MAX(num2) AS num2,
    MAX(num3) AS num3,
    MAX(num4) AS num4,
    MAX(num5) AS num5
FROM dbo.table_name
GROUP BY Id
ORDER BY Id