I’m attempting to filter out missing entries from two data sets by comparing two SQL queries that function properly on their own. However, when I combine them, I encounter a syntax error. Here’s the SQL code I’m using:
SELECT Name_ID FROM [Data_Set1]
WHERE Pool_Type = 'Active'
AND Evaluation_Date = '20151231'
AND Key_Value = '34'
AND Currency = 'EUR'
AND Business_Line = 'KLV'
AND Name_ID NOT IN (
SELECT DISTINCT VD.Name_ID
FROM [Data_Set2] VD
INNER JOIN [Data_Set1] SD
ON VD.Pool_Type = SD.Pool_Type
AND VD.Name_ID = SD.Name_ID
AND VD.Evaluation_Date = SD.Evaluation_Date
AND VD.Key_Value = SD.Key_Value
AND VD.Currency = SD.Currency
WHERE SD.Pool_Type = 'Active'
AND SD.Evaluation_Date = '20151231'
AND SD.Key_Value = '34'
AND SD.Currency ='EUR'
AND SD.Business_Line ='KLV'
)
I’m experiencing a syntax error close to the WHERE
clause. What changes do I need to make in the structure of this query to correctly return the values that are not included in the second part of the query? I should mention that I’m executing this query through a pass-through query in MS Access to communicate with a Microsoft SQL Server.
Thanks in advance for your assistance!