このクエリは、内部値の2番目のクエリでT3.CardCode ='AC0109'を使用すると正常に機能しますが、外部クエリ参照を(T3.CardCode = owt.CardCode)または(T3.CardCode = t1.CardCode)として使用すると、エラーが発生します
マルチパート識別子「owt.cardcode」または「t1.cardcode」をバインドできませんでしたPlzはこの問題の解決に役立ちます
SELECT TOP (100) PERCENT
owt.CardCode,
owt.CardName,
owt.DocDate,
owt.owtsector,
owt.owtzone,
owt.Dscription,
owt.owtrate,
owt.owtqty,
owt.amount,
ISNULL(inw.inwqty,0) AS Expr1,
ISNULL(inw.inwamount, 0) AS Expr2
FROM (SELECT T1.DocDate,
T1.CardCode,
T1.CardName,
T2.ItemCode,
T2.Dscription,
T1.U_STTYPE,
T1.U_SECTOR AS owtsector,
T1.U_ZONE AS owtzone,
SUM(T2.LineTotal) AS amount,
SUM(T2.Quantity) AS owtqty,
T2.CodeBars,
T2.Price AS owtrate
FROM dbo.OWTR AS T1
INNER JOIN dbo.WTR1 AS T2 ON T1.DocEntry = T2.DocEntry
WHERE (T1.DocDate = CONVERT(DATETIME, '2012-03-16 00:00:00', 102))
AND (T1.CardCode = N'ac0109')
AND (T1.U_STTYPE = N'OUTWARD')
AND (T1.U_SECTOR NOT LIKE 'wr%')
GROUP BY T1.DocDate,
T1.CardCode,
T1.CardName,
T2.ItemCode,
T2.Dscription,
T1.U_STTYPE,
T2.Price,
T1.U_SECTOR,
T1.U_ZONE, T2.CodeBars) AS owt
LEFT OUTER JOIN (SELECT T3.DocDate,
T3.CardCode,
T3.CardName,
T3.U_STTYPE,
T4.ItemCode,
T4.Dscription,
SUM(T4.Quantity) AS inwqty,
SUM(T4.LineTotal) AS inwamount
FROM dbo.OWTR AS T3
INNER JOIN dbo.WTR1 AS T4 ON T3.DocEntry = T4.DocEntry
WHERE (T3.DocDate = CONVERT(DATETIME, '2012-03-16 00:00:00', 102))
AND (T3.CardCode = ***owt.CardCode***)
AND (T3.U_STTYPE = N' inward ')
AND (T3.U_SECTOR NOT LIKE ' wr % ')
GROUP BY T3.DocDate,
T3.CardCode,
T3.CardName,
T4.ItemCode,
T4.Dscription,
T3.U_STTYPE) AS inw
ON owt.CardCode = inw.CardCode
AND owt.DocDate = inw.DocDate
AND owt.ItemCode = inw.ItemCode