Let’s try creating a self-contained example – the below code works fine for me.
Can you insert some sample data from your application into this toy code and see if it runs as you expect? If it does, then the problem lies elsewhere in your code.
CREATE TABLE #TempReceivingUnmatchedUPCs (
RecUPC VARCHAR(20),
RecSupplierInvoiceNumber VARCHAR(20),
Foobar VARCHAR(20)
)
CREATE TABLE #tmpDistributorRecords (
DistUPC VARCHAR(20),
DistSupplierInvoiceNumber VARCHAR(20),
Foobar VARCHAR(20)
)
INSERT INTO #TempReceivingUnmatchedUPCs
(RecUPC,RecSupplierInvoiceNumber,Foobar)
VALUES
('ABC',22,'FooA'),
('ABD',23,'BarB'),
('BBB',30,'RecA'),
('BBB',31,'RecB')
INSERT INTO #tmpDistributorRecords
(DistUPC,DistSupplierInvoiceNumber,Foobar)
VALUES
('ABA',22,'FooC'),
('BBD',43,'BarD'),
('BBB',30,'DistA'),
('BBB',32,'DistB')
SELECT *
FROM #TempReceivingUnmatchedUPCs tr
FULL JOIN #tmpDistributorRecords td
ON ( tr.RecUPC=td.DistUPC )
where
tr.RecSupplierInvoiceNumber=td.DistSupplierInvoiceNumber
DROP TABLE #TempReceivingUnmatchedUPCs
DROP TABLE #tmpDistributorRecords
For me, this yields
RecUPC RecSupplierInvoiceNumber Foobar DistUPC DistSupplierInvoiceNumber Foobar
-------------------- ------------------------ -------------------- -------------------- ------------------------- --------------------
BBB 30 RecA BBB 30 DistA
And RecSupplierInvoiceNumber = DistSupplierInvoiceNumber as expected