declare @t table([Key] int,num int)
insert into @t select 1,10
union all select 2,38
union all select 3,8
union all select 4,11
declare @a table([Key] int,num int)
insert into @a select 1,10
union all select 2,38
union all select 4,11
union all select 6,100
union all select 9,121
select b.[key],isnull((a.num+b.num),b.num) as num from @t a,@a b where a.[key]=*b.[key]