Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Finding Missing Records
Message
De
31/10/2017 12:25:14
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Finding Missing Records
Versions des environnements
SQL Server:
SQL Server 2012
Divers
Thread ID:
01655302
Message ID:
01655302
Vues:
57
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform