Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding Missing Records
Message
From
31/10/2017 12:25:14
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Finding Missing Records
Environment versions
SQL Server:
SQL Server 2012
Miscellaneous
Thread ID:
01655302
Message ID:
01655302
Views:
59
Hi,

I've got a mental block at the moment (I've done this many times before) and hoping someone can break the block down for me.
use test

create table Items
(ItemId int,
ItemCode char(1))

insert into Items values (1, 'A')
,(2, 'B')
,(3, 'Z')

create table Branches
(BranchID int,
BranchCode char(1))

insert into Branches values (1, 'C')
,(2, 'D')

create table BranchItems
(BranchItemId int
,ItemID int
,BranchID int
,QtyOnHand int)

insert into BranchItems values (1, 1, 1, 10)
,(2,1,2,15)
,(3,2,1,20)

select ItemCode, BranchCode, QtyOnHand
from branchitems
inner join Items on BranchItems.itemID = Items.ItemId
inner join Branches on BranchItems.BranchID = Branches.BranchID

/*
ItemCode	BranchCode	QtyOnHand
A	C	10
A	D	15
B	C	20
*/

drop table Items
drop table Branches
drop table BranchItems
I need to find items that are missing records in the BranchItems table.

For example in the code above, ItemCode B has no record for BranchCode D.and ItemCode Z has no records in BranchItems at all.

Thanks for any help
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Next
Reply
Map
View

Click here to load this message in the networking platform