Refer below sample
declare @tabX table
(
Sheets int,
PoNo int,
invno int,
ItemId int
)
declare @tabY table
(
Sheets int,
PoNo int,
invno int,
ItemId int
)
insert into @tabX
values (2350,126,3, 111),(2078,129,3,111)
insert into @tabY
values(2300,126,3,111),(50,126,3,111),(2078,129,3,111)
select x.Sheets
into #result
from @tabX X,
@tabY Y
where X.PoNo=y.PoNo
and x.ItemId=y.ItemId
and x.invno=y.invno
Group by x.Sheets
select sum(sheets) from #result