select OPOR.DocEntry, DocDueDate, ItemCode, Dscription, Quantity,
(POR1.Quantity - ISNULL(c.num,0)) as Cnt1 from OPOR inner join POR1 on OPOR.DocEntry = POR1.DocEntry left join
(select isnull(SUM(U_Cnt),0) as num,U_CsCode,U_RecDt,U_ItemCode from [@ENT_QMMR] group by U_CsCode,U_RecDt,U_ItemCode) c on
OPOR.CardCode=c.U_CsCode and OPOR.DocDueDate = c.U_RecDt and POR1.ItemCode=c.U_ItemCode
where OPOR.DocEntry = 1
order by LineNum
(POR1.Quantity - ISNULL(c.num,0)) as Cnt1 from OPOR inner join POR1 on OPOR.DocEntry = POR1.DocEntry left join
(select isnull(SUM(U_Cnt),0) as num,U_CsCode,U_RecDt,U_ItemCode from [@ENT_QMMR] group by U_CsCode,U_RecDt,U_ItemCode) c on
OPOR.CardCode=c.U_CsCode and OPOR.DocDueDate = c.U_RecDt and POR1.ItemCode=c.U_ItemCode
where OPOR.DocEntry = 1
order by LineNum
如果你能夠把你的表結構帖出來﹐那更好說明問題
中怎么可以用POR1表了,你写这个是 from OPOR呀!
(POR1.Quantity - ISNULL(c.num,0)) as Cnt1 from OPOR inner join POR1 on OPOR.DocEntry = POR1.DocEntry left join
(select isnull(SUM(U_Cnt),0) as num,U_CsCode,U_RecDt,U_ItemCode from [@ENT_QMMR] group by U_CsCode,U_RecDt,U_ItemCode) c on
OPOR.CardCode=c.U_CsCode and OPOR.DocDueDate = c.U_RecDt and POR1.ItemCode=c.U_ItemCode
where OPOR.DocEntry = 1
order by LineNum