I've been having a few problem developing a query in MS Access 2010. I have not been able to find a solution on the net as of yet but I feel that I'm really close. Here is what I'm trying to do:
- I have two tables that I'm trying to compare and find like items. Table A is called "DONOTDELETE_FPTable". Table B is called "Imported".
- I'm comparing the same columns in both tables. IP, QID and PORT.
- My goal is to find like records in the Imported table that occur in the DONOTDELETE_FPTable.
- I have a Left Join setup from the DONOTDELETE_FPTable to the Import table on all columns mentioned above.
Problem: I have a situation where a record may have a null value in the column PORT in both tables. I need the query to return:
- All matching records between the two tables that have the same data in all columns
- AND any matching record that has a matching IP, QID and a possible null in the PORT column between the two tables.
Here is the SQL that I have at this point using the "LIKE" criteria. I removed an data where I'm trying to test for the null since I can't get it to work. Thanks for the help ahead of time.
SQL Statement:
SELECT DONOTDELETE_FPExcept.*
FROM
DONOTDELETE_FPExcept
LEFT JOIN Imported
ON
(DONOTDELETE_FPExcept.Port = Imported.PORT)
AND (DONOTDELETE_FPExcept.QID = Imported.QID)
AND (DONOTDELETE_FPExcept.IP = Imported.IP)
WHERE
(((Imported.IP) Like [DONOTDELETE_FPExcept].[ip])
AND ((Imported.qid) Like [DONOTDELETE_FPExcept].[QID])
AND ((Imported.PORT) Like [DONOTDELETE_FPExcept].[Port]));
Here are the is some example data in the table.IP, QID and Port are the columns:
Import Table:
- Record 1: IP: 10.1.1.1 / QID: 225 / Port: 80
- Record 2: IP: 10.1.1.1 / QID: 111 / Port:
- Record 3: IP: 10.1.1.5 / QID: 999 / Port: 8080
- Record 4: IP: 10.1.1.5 / QID: 999 / Port:
Notes: Record 2 - Blank Port is Null. Record 3 should not match and not appear in query.
DONOTDELETE_FPTable
- Record 1: IP: 10.1.1.1 / QID: 225 / Port: 80
- Record 2: IP: 10.1.1.1 / QID: 111 / Port:
Expected Results with Query (Matching Records between two tables with Null):
- Record 1: IP: 10.1.1.1 / QID: 225 / Port: 80
- Record 2: IP: 10.1.1.1 / QID: 111 / Port:
Actually query result (Issue - Null record is missing)
Record 1: IP: 10.1.1.1 / QID: 225 / Port: 80
Record 2: IP: 10.1.1.5 / QID: 999 / Port: