OK, I have a query that is giving me problems. First, here is the query
So, here is the issue. I have serial numbers in 2 tables. tMasterSerialNumbers is the repository for serial numbers, all unassigned (and assigned) serial numbers reside in this table. However, this table was implemented AFTER SNs were already in the other table, CustomerProduct (I know, I don't know how it happened, I wasn't here, just trying to clean it up). Also, we have times when one product will be fulfilled with several serial numbers assigned. When this happens, the record is placed into CustomerProduct with no serial number assigned, but there are the correct number of records in tMasterSerialNumbers with a matching iProductID for the record in CustomerProduct.
I had thought I could do CustomerProduct LEFT OUTER JOIN tMasterSerialNumbers on iProductid and get everything in CustomerProduct even if it isn't in tMasterSerialNumbers, but that isn't happening. If I search by iOwnerId in CustomerProduct, I find 5 records, two of which do not show up in tMasterSerialNumbers.
So, why is my left outer join not working the way I am expecting it to, is my thinking incorrect that it should grab everything from CustomerProduct even if there is no matching record in tMasterSerialNumbers?
Any help would be greatly appreciated and if I haven't provided enough info, let em know what else I should provide.
wb
Code:
SELECT DISTINCT
Product =pm.vchDescription,
Serial_Number =
CASE
WHEN tm.vchSerialNumber LIKE '%invalid' THEN ''
WHEN tm.vchSerialNumber = '' THEN cp.vchSerialNumber
ELSE tm.vchSerialNumber -- Changed this to tMAsterSerialNumbers on 6/8/10
END,
Registration_Key =tm.vchKey, -- Added the Key data on 1/4/2007
Registration_Date =tm.dtAssigned,
Path =pme.vchfilePath,
ProdNum =pm.chProductNumber
FROM Individual i
JOIN CustomerProduct cp ON i.iIndividualID = cp.iOwnerID
LEFT OUTER JOIN tMasterSerialNumbers tm ON cp.iProductId = tm.iProductID -- changed this 6/8/10
JOIN Product_Master pm ON tm.vchProductNumber = pm.chProductNumber
JOIN ProductMaster_Extended pme ON pm.chProductNumber = PME.chProductNumber
WHERE i.iIndividualID = xxxxxx
AND cp.tiRecordStatus = 1
So, here is the issue. I have serial numbers in 2 tables. tMasterSerialNumbers is the repository for serial numbers, all unassigned (and assigned) serial numbers reside in this table. However, this table was implemented AFTER SNs were already in the other table, CustomerProduct (I know, I don't know how it happened, I wasn't here, just trying to clean it up). Also, we have times when one product will be fulfilled with several serial numbers assigned. When this happens, the record is placed into CustomerProduct with no serial number assigned, but there are the correct number of records in tMasterSerialNumbers with a matching iProductID for the record in CustomerProduct.
I had thought I could do CustomerProduct LEFT OUTER JOIN tMasterSerialNumbers on iProductid and get everything in CustomerProduct even if it isn't in tMasterSerialNumbers, but that isn't happening. If I search by iOwnerId in CustomerProduct, I find 5 records, two of which do not show up in tMasterSerialNumbers.
So, why is my left outer join not working the way I am expecting it to, is my thinking incorrect that it should grab everything from CustomerProduct even if there is no matching record in tMasterSerialNumbers?
Any help would be greatly appreciated and if I haven't provided enough info, let em know what else I should provide.
wb