我有这个加入:
LEFT MERGE JOIN
(SELECT
VOUCHER, TAXITEMGROUP, TAXCODE, TAXAMOUNT, TAXAMOUNTCUR, SOURCERECID, GENERALJOURNALACCOUNTENTRY
FROM
##TGJAE TT
WHERE
(TT.TAXCODE LIKE 'RISR%')) TTRISR
AND TT.POSTINGTYPE IN (14, 236, 71)
AND TT.TRANSDATE BETWEEN @FECHA_INI AND @FECHA
AND TT.TAXORIGIN = 11
AND ON C1.TT_VOUCHER = TTRISR.VOUCHER
AND C1.TT_SOURCERECID = TTRISR.SOURCERECID
AND C1.TT_TAXITEMGROUP = TTRISR.TAXITEMGROUP
AND TTRISR.GENERALJOURNALACCOUNTENTRY = PRO.TTGJAEF_GENERALJOURNALACCOUNTENTRY
但是当我使用SQL Server Management Studio执行时,我收到此错误:
关键字“AND”
附近的语法不正确
我发现我的AND
条款没有问题,有人能解释一下我的加入有什么问题吗?此致
答案 0 :(得分:2)
格式正确的代码总是更容易阅读和调试。
您到处都有WHERE
和ON
条款。
LEFT MERGE JOIN
(
SELECT VOUCHER
,TAXITEMGROUP
,TAXCODE
,TAXAMOUNT
,TAXAMOUNTCUR
,SOURCERECID
,GENERALJOURNALACCOUNTENTRY
FROM ##TGJAE TT
WHERE TT.TAXCODE LIKE 'RISR%'
AND TT.POSTINGTYPE IN( 14,236,71)
AND TT.TRANSDATE between @FECHA_INI AND @FECHA
AND TT.TAXORIGIN = 11
) TTRISR
ON C1.TT_VOUCHER = TTRISR.VOUCHER
AND C1.TT_SOURCERECID = TTRISR.SOURCERECID
AND C1.TT_TAXITEMGROUP = TTRISR.TAXITEMGROUP
AND TTRISR.GENERALJOURNALACCOUNTENTRY = PRO.TTGJAEF_GENERALJOURNALACCOUNTENTRY
答案 1 :(得分:1)
您在第6行/第7行开头使用AND ON
。您可能想要删除AND
。