0

我正在尝试调试此查询但没有任何成功。在下面的代码中,如果我注释掉 Pt.pt_id_nbr 它可以工作,否则查询会持续执行很长时间

Declare @sAlias         char(1),
 @sGQOrgId  char(3),
 @sID            char(12),
 @sType        char(1),
 @sSource    char(2),
 @dcLocationId numeric(18, 0) = NULL

 set @sAlias='N'
 set @sGQOrgId  =''
 Set @sID     =''
 Set @sType       ='M'
 Set @sSource  ='MD'

SELECT DISTINCT 
         '' 'ImportID',d.GQOrgId, d.DeviceId
        --,isnull(Pt.Pt_id_nbr,0)as Pt_id_nbr
        --,Pt.pt_id_nbr works if commented out else the query keeps executing for a long time
        , DeviceDesc = LTRIM(RTRIM(d.DeviceDesc)), d.Source, 
                      SourceDesc = LTRIM(RTRIM(s.SourceDesc))
        FROM    GasQuality.dbo.Device AS d WITH (NoLock)
        JOIN    GasQuality.dbo.SourceCodes AS s WITH (NoLock)
        ON      s.Source = d.Source
        left join elm_qa.elm.dbo.pt_sys_xref as Pt WITH (NoLock)
        ON    d.DeviceID = Pt.REF_VAL  and (Pt.OLD_SYS_ID = 'PK' and Pt.VAL_TYPE_CD = 'OM' ) 
        WHERE s.Type = @sType AND
            d.GQOrgId LIKE RTRIM(@sGQOrgId) + '%'
            AND d.Source LIKE RTRIM(@sSource) + '%'
            AND d.DeviceId LIKE RTRIM(@sID) + '%'

        ORDER BY d.GQOrgId, d.DeviceId, d.Source
4

1 回答 1

0

然后我会尝试将它作为一个组而不是一个独特的。

于 2012-11-13T17:37:34.050 回答