Hello ,
Try this Query .
create Table #tmptable
(
project int not null ,
godown varchar(20) not null
)
insert into #tmptable values(0,11)
insert into #tmptable values(0,12)
insert into #tmptable values(1,11)
insert into #tmptable values(1,12)
insert into #tmptable values(2,11)
insert into #tmptable values(2,12)
create Table #tmptable1
(
project int not null ,
godown varchar(20) not null,
product int not null ,
qty int not null
)
insert into #tmptable1 values(0,11,22,5)
insert into #tmptable1 values(1,12,23,6)
insert into #tmptable1 values(2,11,24,7)
select X.Project , X.GoDown,Y.product , X.Qty from
(select a.project as Project, a.godown as GoDown, b.product as Product,
(case when b.qty is null then 0 else b.qty end )Qty from #tmptable a left outer join #tmptable1 b on a.project=b.project
and a.godown=b.godown) X
inner join
(select project, product from #tmptable1) Y
on X.Project=Y.project
thanks