Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

JOIN ROWS

$
0
0

Hi,

I need help on the below please

DECLARE @t TABLE
(
ID int,
Color1 int,
Color2 int,
Color3 int
)

INSERT INTO @t
VALUES (1, NULL, NULL, 5)
, (1, NULL, 10, NULL)
,(1, 0, NULL, NULL)
,(2, NULL, NULL, 54)
, (2, NULL, 140, NULL)
,(2, 0, NULL, NULL)

SELECT * FROM @t

Returns the below

ID  Color1 Color2 Color3
1   NULL    NULL    5
1   NULL    10       NULL
1   0          NULL   NULL
2   NULL    NULL   54
2   NULL    140     NULL
2   0          NULL   NULL

Each ID will always have 3 rows, I would like to merge the cells for each ID into one row ie

ID  Color1 Color2 Color3
1    0        10       5
2   0         140     54

Please help?


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>