select s.part_no
,s.part_name
,s.uom
,i.Invoice_Quantity
,r.Return_Quantity
,p.Issue_Quantity
,sr.Quantity
,rp.Return_Quantity
,er.Quantity
from dbo.dri_Stock as s
left join
(
select part_no,sum(Invoice_Quantity) as Invoice_Quantity
from dbo.dri_InwardEntry
where month(_date)=6 and year(_date)=2012
group by part_no
) as i
on s.part_no=i.part_no
left join
(
select part_no,sum(Return_Quantity) as Return_Quantity
from dbo.dri_ReturnToCustomer
where month(date)=6 and year(date)=2012
group by part_no
) as r
on s.part_no=r.part_no
left join
(
select part_no,sum(Issue_Quantity) as Issue_Quantity
from dbo.dri_IssueToProd
where month(date)=6 and year(date)=2012
group by part_no
)as p
on s.part_no=p.part_no
left join
(
select part_no,sum(Quantity) as Quantity
from dbo.dri_ShortReceipt
where month(date)=6 and year(date)=2012
group by part_no
)as sr
on s.part_no=sr.part_no
left join
(
select part_no,sum(Return_Quantity) as Return_Quantity
from dbo.dri_ReceiptFromProd
where month(date)=6 and year(date)=2012
group by part_no
)as rp
on s.part_no=rp.part_no
left join
(
select part_no,sum(Quantity) as Quantity
from dbo.dri_ExcessReceipt
where month(date)=6 and year(date)=2012
group by part_no
)as er
on s.part_no=er.part_no
where i.invoice_quantity>0
我想在我的输出中添加一个列,即stockBalance
我怎样才能做到这一点:
计算 StockBalance 的公式为(i.Invoice_Quantity + rp.Return_Quantity + er.Quantity) - (r.Return_Quantity + p.Issue_Quantity + sr.Quantity)