select
v_ex_currentstockquery.cWhCODE as '仓别',
v_ex_currentstockquery.cWhName as '仓库',
b.cInvCode as '物料编码',
inventory.cinvname as '存货名称',
v_ex_currentstockquery.cInvStd as '规格型号',
isnull(v_ex_currentstockquery.iQuantity,0) as '数量',
b.iNatUnitPrice as '最新价格 ',
isnull(v_ex_currentstockquery.iQuantity,0)*b.iNatUnitPrice as '合计'
from v_ex_currentstockquery
left join (
select iNatUnitPrice,PO_Podetails.cInvCode from PO_Podetails,
(select MAX(id) as id ,cInvCode from PO_Podetails
group by cInvCode)a
where PO_Podetails.ID=a.id and
PO_Podetails.cInvCode=a.cinvcode)
b
on b.cInvCode= v_ex_currentstockquery.cinvcode
left join inventory on inventory.cinvcode=b.cinvcode
where v_ex_currentstockquery.cWhCode in
('100','101','102','103','104','105','106','107','108','120','121','122','123','124',
'125','126','127','128','129','200','201','202','203','204','205','206','207','208','209',
'210','211','212','220','221','222','223','224','225','226','227','228','302','303','304','
305','306','307','308','309')
AND isnull(v_ex_currentstockquery.iQuantity,0) <>'0' order by 物料编码