日期:2014-05-17 浏览次数:20386 次
select type 出入库,storeNO 单据编号,ID,store 仓库名称,storeAdmin 库管员,source,storeDate 日期,price 金额 from
((select type,storeNO,store,storeAdmin,source,storeDate,SUM(price) price
from
(select 'out' type,o.outStoreNO storeNO,st.storeName store, st.storeID ID,
u.userName storeAdmin,c.canteenName source,o.outDate storeDate,
case when p.quantity=0 then p.quantity else o.outQuantity*(p.price/p.quantity) end price
from OutStore o
left join Store st on o.store=st.storeID
left join [User] u on o.storeAdmin=u.userID
left join Canteen c on o.canteen=c.CanteenID
left join(select * from StoreQuantity s left join Product pro on s.product=pro.productID where s.store=2) p
on o.product=p.productID where o.store=2 ) ou
group by type,storeNO,store,storeAdmin,source,storeDate)
union
(select type,storeNO,store,storeAdmin,source,storeDate,SUM(price) price
from
(select 'in' type,i.inStoreNO storeNO,st.storeName store,st.storeID ID,
u.userName storeAdmin,sp.supplierName source,i.inDate storeDate,
inPrice price &nbs