显式连接语法

2022-08-06 00:00:00 sql sql-server inner-join

我正在增强一个旧的应用程序,该应用程序使用与下面类似的查询。我想转换语法以开始使用显式连接语法。下面的‘EXPLICIT JOIN语法’查询是什么:

Select
       DTL.DetailId
     , HDR.PersonId
from
       CMPN.Header             HDR
     , CMPN.Detail             DTL
     , CMPN.DetailStatus       DST
     , CMPN.AdjustmentsDetails CAD
where
       HDR.HeaderId                      = DTL.HeaderId
       and DTL.DetailId                  = DST.DetailId
       and DTL.DetailId                  = CAD.DetailId
       and DST.DetailStatusCode          = 'Approved'
       and DST.ExpirationTimestamp IS NULL
       and HDR.Group                     = 'Group A'
;

解决方案

试试:

SELECT
    DTL.DetailId, HDR.PersonId
FROM
    CMPN.Header HDR
INNER JOIN
    CMPN.Detail DTL ON HDR.HeaderId = DTL.HeaderId
INNER JOIN
    CMPN.DetailStatus DST ON DTL.DetailId = DST.DetailId
INNER JOIN
    CMPN.AdjustmentsDetails CAD ON DTL.DetailId = CAD.DetailId
WHERE
    DST.DetailStatusCode = 'Approved'
    AND DST.ExpirationTimestamp IS NULL
    AND HDR.Group = 'Group A';

相关文章