如果我在第二个查询中使用 T3.CardCode = 'AC0109' 来获取内向值但如果我使用外向查询引用作为 (T3.CardCode = owt.CardCode) 或 (T3.CardCode = t1.CardCode) 则此查询工作正常上升错误
多部分标识符“owt.cardcode”或“t1.cardcode”无法绑定请帮我解决这个问题
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