Sql-server – Merging almost unique rows together

sql server

I have this table

enter image description here

And i need have this (In source table are thousands values)

enter image description here

How can i do that ?

Here is example database: http://sqlfiddle.com/#!3/4278d

Thank you.

Best Answer

Assuming that each row in the source table only has either variable1, 2 or 3 populated, and there is only one such row for each combination, then this is probably the simplest approach:

SELECT Name, Column2, 
  MAX(Variable1),
  MAX(Variable2),
  MAX(Variable3)
FROM dbo.DataTable
GROUP BY Name, Column2;

SQLfiddle