ParaDoX86
ParaDoX86

Reputation: 39

T-SQL Merging data

I've imported data from an XML file by using SSIS to SQL Server. The result what I got in the database is similar to this:

+-------+---------+---------+-------+
|  ID   |  Name   |  Brand  | Price |
+-------+---------+---------+-------+
| 2     | NULL    | NULL    | 100   |
| NULL  | SLX     | NULL    | NULL  |
| NULL  | NULL    | Blah    | NULL  |
| NULL  | NULL    | NULL    | 100   |
+-------+---------+---------+-------+

My desired result would be:

+-------+---------+---------+-------+
|  ID   |  Name   |  Brand  | Price |
+-------+---------+---------+-------+
| 2     | SLX     | Blah    | 100   |
+-------+---------+---------+-------+

Is there a pretty solution to solve this in T-SQL? I've already tried it with a SELECT MAX(ID) and then a GROUP BY ID, but I'm still stuck with the NULL values. Also I've tried it with MERGE, but also a failure. Could someone give me a direction where to search further?

Upvotes: 1

Views: 102

Answers (1)

John Bell
John Bell

Reputation: 2350

You can select MAX on all columns....

SELECT MAX(ID), MAX(NAME), MAX(BRAND), MAX(PRICE)
FROM [TABLE]

Click here for a fiddley fidd fiddle...

Upvotes: 2

Related Questions