如果我在其中一个连接中添加AND条件,则查询Where子句运行正常

时间:2018-01-12 15:20:51

标签: sql oracle join linked-server

我在加入where条件后使用AND子句时遇到以下错误:

  

OLE DB提供程序" OraOLEDB.Oracle"对于链接服务器" xyz"回   消息" ORA-01403:未找到数据"。 Msg 7346,Level 16,State 2,Line   1无法从OLE DB提供程序获取该行的数据   " OraOLEDB.Oracle"对于链接服务器" xyz"。

以下查询工作正常:

SELECT DISTINCT a.FileNumber, a.FileSub, a.CurrentBatchRecordID, b.BatchName, b.BatchID,b.BatchStatusID,
 b.CreateDate, b.IOGCBatch,e.Area,e.LandDistrict,f.province,f.name
 FROM Lease.tFileSubReviewers AS a
  LEFT OUTER JOIN Lease.tBatchHeader AS b ON b.RecordID = a.CurrentBatchRecordID
  LEFT OUTER JOIN Admin.tUser AS c 
  ON c.RecordID = a.ReviewerID    
 LEFT OUTER JOIN Lease.tFileSubDetail as e on a.FileNumber=e.FileNumber 
    LEFT OUTER join  openquery("xyz",
 'SELECT Code ,RTRIM(PROVINCE) AS PROVINCE,RTRIM(NAME) AS NAME FROM CSL_T_AREA order by province') as f 
 on f.code=e.Area where a.ReviewerID=179 

但是如果我在openquery join之前添加AND条件加入,如下所示:

 SELECT DISTINCT a.FileNumber, a.FileSub, a.CurrentBatchRecordID, b.BatchName, b.BatchID,b.BatchStatusID,
 b.CreateDate, b.IOGCBatch,e.Area,e.LandDistrict,f.province,f.name
 FROM Lease.tFileSubReviewers AS a
  LEFT OUTER JOIN Lease.tBatchHeader AS b ON b.RecordID = a.CurrentBatchRecordID
  LEFT OUTER JOIN Admin.tUser AS c 
  ON c.RecordID = a.ReviewerID 

 LEFT OUTER JOIN Lease.tFileSubDetail as e on a.FileNumber=e.FileNumber **and a.FileSub =e.FileSub**  
  LEFT OUTER join  openquery("xyz",
 'SELECT Code ,RTRIM(PROVINCE) AS PROVINCE,RTRIM(NAME) AS NAME FROM CSL_T_AREA order by province') as f 
 on f.code=e.Area where a.ReviewerID=179  

我收到错误,如上图所示。即使我在第二个查询的末尾没有包含where条件,查询运行正常。

任何人都可以帮我吗?

感谢。

0 个答案:

没有答案