简体   繁体   中英

Msg 156, Level 15, State 1, Line 5 Incorrect syntax near the keyword 'LEFT'. Msg 156, Level 15, State 1, Line 6 Incorrect syntax near 'b'

USE [pfebd]
SELECT *
FROM TBCSBONNV a
WHERE TBCSJRNE<=20210422 AND TBCSECHE >=20210422 AND TBCSDBSC<=20210422 
LEFT JOIN 
(SELECT DISTINCT CPGCTGS ,CPGCPT,CPTENUM FROM CPTAXNV )b
ON a.TBCSAGCC=b.CPGCTGS AND a.TBCSNUCC=b.CPTENUM;

JOIN is an operator in the FROM clause. The WHERE clause follows the FROM clause. So you seem to want:

SELECT c.*, a.*
FROM TBCSBONNV c LEFT JOIN
     (SELECT DISTINCT CPGCTGS, CPGCP, CPTENUM
      FROM CPTAXNV a
     ) a
     ON c.TBCSAGCC = a.CPGCTGS AND c.TBCSNUCC = a.CPTENUM;
WHERE c.TBCSJRNE <= 20210422 AND
      c.TBCSECHE >= 20210422 AND
      c.TBCSDBSC <= 20210422 ;

I replaced the table aliases with aliases that seem related to the table names TB C SBONNV and CPT A XNV.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM