Hi All!,
I have a question regarding SQL Queries and nulls.
This is my scenario.
I am comparing two tables, tblImportAuditTable and tblDevices. There are 5 fields that are being compared to see if they are the same. The primary key in tblDevices is the Serial Number. I want the query to operate such that if any of the 5 fields that are being compared are not the same, then I want those records returned. The problem I am having is that the AssetTag field in either table can be null in some circumstances. When this is the case, the query returns the record where the AssetTag is null. I DON'T want that to happen. I want it so that if the Query sees the AssetTag field in both tblImportAuditTable and tblDevices as null, I want it to see that as a match and not return the record. At the moment, the opposite happens.
The query is below. Any suggestions? Thanks in advance!
SELECT tblImportAuditTable.Device, tblImportAuditTable.AssetTag, tblImportAuditTable.Serial, tblImportAuditTable.StoreLocation, tblImportAuditTable.Status
FROM tblImportAuditTable LEFT JOIN tblDevices ON (tblImportAuditTable.Status = tblDevices.Status) AND (tblImportAuditTable.StoreLocation = tblDevices.StoreLocation) AND (tblImportAuditTable.AssetTag = tblDevices.AssetTag) AND (tblImportAuditTable.Device = tblDevices.Device) AND (tblImportAuditTable.Serial = tblDevices.Serial)
WHERE (((tblDevices.Serial) Is Null));
I have a question regarding SQL Queries and nulls.
This is my scenario.
I am comparing two tables, tblImportAuditTable and tblDevices. There are 5 fields that are being compared to see if they are the same. The primary key in tblDevices is the Serial Number. I want the query to operate such that if any of the 5 fields that are being compared are not the same, then I want those records returned. The problem I am having is that the AssetTag field in either table can be null in some circumstances. When this is the case, the query returns the record where the AssetTag is null. I DON'T want that to happen. I want it so that if the Query sees the AssetTag field in both tblImportAuditTable and tblDevices as null, I want it to see that as a match and not return the record. At the moment, the opposite happens.
The query is below. Any suggestions? Thanks in advance!
SELECT tblImportAuditTable.Device, tblImportAuditTable.AssetTag, tblImportAuditTable.Serial, tblImportAuditTable.StoreLocation, tblImportAuditTable.Status
FROM tblImportAuditTable LEFT JOIN tblDevices ON (tblImportAuditTable.Status = tblDevices.Status) AND (tblImportAuditTable.StoreLocation = tblDevices.StoreLocation) AND (tblImportAuditTable.AssetTag = tblDevices.AssetTag) AND (tblImportAuditTable.Device = tblDevices.Device) AND (tblImportAuditTable.Serial = tblDevices.Serial)
WHERE (((tblDevices.Serial) Is Null));