如何解决多部分标识符错误?

时间:2016-04-08 06:05:45

标签: sql sql-server sql-server-2008

执行以下查询时,我收到此错误:

  

Msg 4104,Level 16,State 1,Line 3   无法绑定多部分标识符“LEAS.BLDGID”。   Msg 4104,Level 16,State 1,Line 3   无法绑定多部分标识符“LEAS.LEASID”。   **当我运行查询的上半部分时出错!!(只需要第1部分,因为数据出错!! ****

SELECT 1 
    FROM NOTE 
    LEFT JOIN INSL ON INSL.TABLEID =  'LEAS' AND INSL.TABLEKEY = NOTE.LEASID 
    WHERE NOTE.BLDGID = LEAS.BLDGID AND NOTE.LEASID = LEAS.LEASID AND NOTE.REF1 = 'INSURAN'  
        AND NOTE.REF2 = 'REMIND' AND NOTE.ACTIONED <> 'C' AND NOTE.NOTEDATE = INSL.INSLEND 
        AND  INSL.INSLEND < '2016-04-07' AND NOT EXISTS (
            SELECT 1 
            FROM INSL I2 
            WHERE I2.TABLEKEY = INSL.TABLEKEY AND I2.TABLEID = INSL.TABLEID AND I2.INSLCODE = INSL.INSLCODE 
                    AND I2.INSLEND > INSL.INSLEND
            )

完整查询

    SELECT TOP 301
        LEAS.LEASID ,
        LEAS.BLDGID ,
        LEAS.SUITID ,
        SUIT.ADDRESS ,
        LEAS.OCCPNAME ,
        LEAS.RENTSTRT ,
        LEAS.EXPIR ,
        LEAS.VACATE ,
        LEAS.STOPBILLDATE ,
        LEAS.INSEXP ,
        LEAS.OCCPSTAT ,
        LEAS.PRTSTAT ,
        LEAS.PERMITCR ,
        LEAS.LEASSTOP ,
        LEAS.MAXLATE ,
        LEAS.LASTDATE ,
        LEAS.USERID ,
        LEAS.EXCL5YR ,
        LEAS.STYPID ,
        LEAS.REPFREQ ,
        LEAS.REQADJ ,
        LEAS.PCTGBASE ,
        LEAS.NATURAL ,
        LEAS.NUMCOPY ,
        LEAS.GENERATION ,
        LEAS.ADDLSPACE ,
        LEAS.PRIMARYCHGS ,
        LEAS.HEADLEAS ,
        LEAS.DEPARTMENT ,
        LEAS.PREPAYTAXTERM ,
        LEAS.HEAD ,
        LEAS.INVOICEGRP ,
        LEAS.LEASE_YRS ,
        LEAS.LEASE_MTHS ,
        LEAS.LEASE_DAYS ,
        LEAS.INVPRINT ,
        LEAS.CASUALCARPARKS ,
        LEAS.TAXEXEMPT ,
        LEAS.AUTOEXCEPTION ,
        LEAS.FASBEXCEPTION ,
        LEAS.PERCENTRENT ,
        LEAS.INV_AUTOE ,
        LEAS.SMT_AUTOE ,
        LEAS.LATEPAYER
FROM    LEAS ,
        SUIT
WHERE   SUIT.BLDGID = LEAS.BLDGID
        AND SUIT.SUITID = LEAS.SUITID
        AND ( LEAS.BLDGID IN ( '140056', '140063', '140070', '140104',
                               '140137', '140138', '140151', '140253',
                               '140345', '140419', '140444', '140508',
                               '140509', '140522', '140542', '140546',
                               '140570', '140575', '140579', '140590',
                               '140623', '140625', '140626', '140662',
                               '140666', '140670', '140760', '140763',
                               '140788', '140789', '140793', '140799',
                               '140811', '140852', '140858', '140861',
                               '140867', '140875', '140880', '140881',
                               '140917', '140938' )
              AND LEAS.OCCPSTAT IN ( 'C', 'N' )
              AND EXISTS ( SELECT   1
                           FROM     NOTE
                                    LEFT JOIN INSL ON INSL.TABLEID = 'LEAS'
                                                      AND INSL.TABLEKEY = NOTE.LEASID
                           WHERE    NOTE.BLDGID = LEAS.BLDGID
                                    AND NOTE.LEASID = LEAS.LEASID
                                    AND NOTE.REF1 = 'INSURAN'
                                    AND NOTE.REF2 = 'REMIND'
                                    AND NOTE.ACTIONED <> 'C'
                                    AND NOTE.NOTEDATE = INSL.INSLEND
                                    AND INSL.INSLEND < '2016-04-07'
                                    AND NOT EXISTS ( SELECT 1
                                                     FROM   INSL I2
                                                     WHERE  I2.TABLEKEY = INSL.TABLEKEY
                                                            AND I2.TABLEID = INSL.TABLEID
                                                            AND I2.INSLCODE = INSL.INSLCODE
                                                            AND I2.INSLEND > INSL.INSLEND ) )
            )
ORDER BY LEAS.SUITID  

1 个答案:

答案 0 :(得分:4)

我想你错过了一个支架。请通过添加结束括号@

进行验证
'140917', '140938' ))

在以下where where子句中

AND ( LEAS.BLDGID IN ( '140056', '140063', '140070', '140104',
                           '140137', '140138', '140151', '140253',
                           '140345', '140419', '140444', '140508',
                           '140509', '140522', '140542', '140546',
                           '140570', '140575', '140579', '140590',
                           '140623', '140625', '140626', '140662',
                           '140666', '140670', '140760', '140763',
                           '140788', '140789', '140793', '140799',
                           '140811', '140852', '140858', '140861',
                           '140867', '140875', '140880', '140881',
                           '140917', '140938' )