2

=* 由于存在(RIGHT OUTER JOIN) 运算符,我们遇到了 SQL Server 2012 问题 。

谁能告诉我在 SQL Server 2008 上正常工作的以下 SQL 的 SQL Server 2012 的正确语法是什么?

  SELECT 
    ProcessCode, 
    ProcessDesc, 
    DisciplineDesc, 
    ValidProcessName .DisciplineCode 
 FROM 
    ValidName, ValidProcessName 
 WHERE
    ValidProcessName.DisciplineCode =* ValidName.DisciplineCode 
 ORDER BY 
    ProcessCode
4

2 回答 2

5

所以首先要注意的是RIGHT连接与连接相同LEFT,但表顺序交换了。

出于这个原因和可读性,我个人从不使用RIGHT连接(我从左到右阅读,因此查询对我来说更有意义)。

所以你的查询可能变成:

SELECT <missing_alias>.ProcessCode
     , <missing_alias>.ProcessDesc
     , <missing_alias>.DisciplineDesc
     , ValidProcessDiscipline.DisciplineCode
FROM   ValidProcessDiscipline
 LEFT
  JOIN ValidProcess
    ON ValidProcess.DisciplineCode = ValidProcessDiscipline.DisciplineCode
ORDER
    BY ProcessCode

抓取所有ValidProcessDiscipline记录和任何匹配的ValidProcess记录。

当然,如果您坚持使用RIGHT联接,那么:

SELECT <missing_alias>.ProcessCode
     , <missing_alias>.ProcessDesc
     , <missing_alias>.DisciplineDesc
     , ValidProcessDiscipline.DisciplineCode
FROM   ValidProcess
 RIGHT
  JOIN ValidProcessDiscipline
    ON ValidProcessDiscipline.DisciplineCode = ValidProcess.DisciplineCode 
ORDER
    BY ProcessCode
于 2013-09-18T12:36:18.330 回答
4

这是:

SELECT 

   ProcessCode, 
   ProcessDesc, 
   DisciplineDesc, 
   ValidProcessDiscipline.DisciplineCode 

FROM 

   ValidProcess RIGHT OUTER JOIN ValidProcessDiscipline 

ON

   ValidProcessDiscipline.DisciplineCode = ValidProcess.DisciplineCode 

ORDER BY 

   ProcessCode
于 2013-09-18T12:31:03.937 回答