0

我有以下查询,但没有给我想要的输出:

   SELECT DBO.[PLAN].DATE, 
       DBO.TBRECEIPT.RECEIPTDATE, 
       DBO.TBRECEIPTLINE.RECEIPTQTY, 
       DBO.PLAN_LINE.PALLETS 
FROM   DBO.TBRECEIPT 
       INNER JOIN DBO.TBRECEIPTLINE 
               ON DBO.TBRECEIPT.PKID = DBO.TBRECEIPTLINE.RECEIPTID 
       INNER JOIN DBO.[PLAN] 
                  INNER JOIN DBO.PLAN_LINE 
                          ON DBO.[PLAN].PKID = DBO.PLAN_LINE.PLANID 
               ON DBO.TBRECEIPT.RECEIPTDATE = DBO.[PLAN].DATE 

我必须错误地关联这两组标题/行表。
任何人都可以发现错误吗?

谢谢

4

1 回答 1

0
SELECT DBO.[PLAN].DATE, 
       DBO.TBRECEIPT.RECEIPTDATE, 
       DBO.TBRECEIPTLINE.RECEIPTQTY, 
       DBO.PLAN_LINE.PALLETS 
FROM   DBO.TBRECEIPT 
       INNER JOIN DBO.TBRECEIPTLINE 
               ON DBO.TBRECEIPT.PKID = DBO.TBRECEIPTLINE.RECEIPTID 
       INNER JOIN DBO.[PLAN] 
                  --No Condition? Problem 
                  INNER JOIN DBO.PLAN_LINE 
                          ON DBO.[PLAN].PKID = DBO.PLAN_LINE.PLANID 
               ON DBO.TBRECEIPT.RECEIPTDATE = DBO.[PLAN].DATE 

试试这个:我会推荐你​​使用ALIAS来获得更好的代码实践。

SELECT P.DATE, 
       R.RECEIPTDATE, 
       RL.RECEIPTQTY, 
       PL.PALLETS 
FROM   DBO.TBRECEIPT R 
       INNER JOIN DBO.TBRECEIPTLINE RL 
               ON R.PKID = RL.RECEIPTID 
       INNER JOIN DBO.[PLAN] P 
               ON R.RECEIPTDATE = P.DATE 
       INNER JOIN DBO.PLAN_LINE PL 
               ON P.PKID = PL.PLANID 
于 2013-08-19T05:02:44.463 回答