declare @tb table (a varchar(10),b varchar(10),c int,c2 int,c3 int,c4 int)
insert into @tb select 'w','d',12,null,4,null
insert into @tb select 'w','d',null,5,null,null
insert into @tb select 'w','d',null,null,null,8select a,b,
(select top 1 c from @tb where a=t.a and b=t.b and c is not null)as c,
(select top 1 c2 from @tb where a=t.a and b=t.b and c2 is not null)as c2,
(select top 1 c3 from @tb where a=t.a and b=t.b and c3 is not null)as c3,
(select top 1 c4 from @tb where a=t.a and b=t.b and c4 is not null)as c4
from @tb t
group by a,ba b c c2 c3 c4
w d 12 5 4 8