Say I have the following table with a unique ID and 4 attribute columns...
|ID| |Attribute 1| |Attribute 2| |Attribute 3| |Attribute 4|
1 RED NULL BLUE GREEN
2 NULL BLUE GREEN NULL
3 GREEN YELLOW NULL BLUE
4 YELLOW NULL NULL GREEN
What can I use in SQL Server 2014 to say: If attribute 1 is NULL, use attribute 2, but if attribute 2 is NULL use Attribute 3, and so on... I was going to use a CASE statement, but I'm not sure how to go about it beyond CASE WHEN Attribute 1 IS NULL THEN Attribute 2, but then what if attribute 2 is NULL? How would I then select the next column value that is not NULL?
I want to somehow get the above, to this...
|ID| |Attribute 1| |Attribute 2| |Attribute 3| |Attribute 4|
1 RED BLUE GREEN NULL
2 BLUE GREEN NULL NULL
3 GREEN YELLOW BLUE NULL
4 YELLOW GREEN NULL NULL