I work on SQL server 2012 I need to count missing rows Part id that exist on table #parts
and not exist on table #tradecode
create table #searchdata
(
plid int,
codetypeid int
)
insert into #searchdata
(plid,codetypeid)
values
(84459,877490)
create table #parts
(
partid int,
plid int
)
insert into #parts(partid,plid)
values
(758901,84459),
(808091,84459),
(509030,84459),
(7090321,84459),
(32453,84459),
(45563,84459)
create table #tradecode
(
partid int,
codetypeid int
)
insert into #tradecode(partid,codetypeid)
values
(758901,877490),
(808091,877490)
select p.plid,s.codetypeid,count(p.partid) as countmissingParts
from #parts p
inner join #searchdata s on s.plid=p.plid
left join #tradecode t on t.codetypeid=s.codetypeid
where t.partid is null
group by p.plid,s.codetypeid
drop table #searchdata
drop table #parts
drop table #tradecode
Expected result is :slight_smile:
plid codetypeid countmissingParts
84459 877490 4
actually I put data for search and filter on table search data
I need to get data exist on search data table and that exist on parts table
but not exist on table trade code
so it must have 4 parts or rows missing but statement above
return null rows
why and how to solve