You also need the final select that joins the two tables - for example like this:WITH t1 AS( SELECT a.gldoc, a.GLJELN FROM OPENQUERY( symprod_etldev, 'select * from proddta.f0911 where glco = ''10002'' and globj = ''445791'' ' )a LEFT OUTER JOIN ( SELECT GLDOC, GLJELN FROM F0911 WHERE GLCO = '10002' AND GLOBJ = '445791' )b ON a.gldoc = b.gldoc AND a.gljeln = b.gljeln WHERE b.GLJELN IS NULL),T2 AS( SELECT * FROM OPENQUERY( symprod_etldev, 'select * from proddta.f0911 where glco = ''10002'' and globj = ''445791'' ' ))SELECT * FROM t1 INNER JOIN t2 ON t1.gldoc = t2.gldoc