select f.billID,f.billType,i.itemId,i.name,i.spec,s.unit,sum(isnull(c.Qty,0)) as srQty,i.price as srprice,c.amount,sum(isnull(s.Qty,0)) as zcQty,
i.price as zcprice,s.amount as hamount
from ERP_Item i inner join Finance_Accept f on f.enterpriseAccount=i.enterpriseAccount
inner join ERP_SellOutDetail s on s.itemID=i.itemID and s.enterpriseAccount=i.enterpriseAccount
inner join ERP_StorageInDetail c on c.itemID=i.itemID and c.enterpriseAccount=i.enterpriseAccount
inner join ERP_StorageOut e on i.enterpriseAccount=e.enterpriseAccount
where (i.name like '%%' or i.itemID LIKE '%%') and e.storageOutDate between '2015-09-28' and '2015-10-28'
group by i.itemID,i.name,i.spec,s.unit,s.amount,f.billType,f.billID,i.price,c.amount
order by sum(isnull(c.amount,0))
i.price as zcprice,s.amount as hamount
from ERP_Item i inner join Finance_Accept f on f.enterpriseAccount=i.enterpriseAccount
inner join ERP_SellOutDetail s on s.itemID=i.itemID and s.enterpriseAccount=i.enterpriseAccount
inner join ERP_StorageInDetail c on c.itemID=i.itemID and c.enterpriseAccount=i.enterpriseAccount
inner join ERP_StorageOut e on i.enterpriseAccount=e.enterpriseAccount
where (i.name like '%%' or i.itemID LIKE '%%') and e.storageOutDate between '2015-09-28' and '2015-10-28'
group by i.itemID,i.name,i.spec,s.unit,s.amount,f.billType,f.billID,i.price,c.amount
order by sum(isnull(c.amount,0))