日期:2014-05-18 浏览次数:20522 次
select invent.cDepotId,invent.cprodid ,case when in_iQuantity is null then 0 else in_iQuantity end in_iQuantity ,case when in_iSuCentiare is null then 0 else in_iSuCentiare end in_iSuCentiare ,case when in_iSuAmt is null then 0 else in_iSuAmt end in_iSuAmt ,case when ou_iQuanTity is null then 0 else ou_iQuanTity end ou_iQuanTity ,case when ou_iSuCentiare is null then 0 else ou_iSuCentiare end ou_iSuCentiare from ( select depot.cDepotId,cDepotName,invent.cClassId,cProdid,cProdName,iCentiare,cSpecif,cUnit from invent FULL OUTER JOIN depot on invent.cProdid<>depot.cDepotId )invent left join ( select cDepotId,paperlog.cProdId,sum(iQuanTity)in_iQuanTity,sum(iSuCentiare)in_iSuCentiare,sum(iSuAmt)in_iSuAmt from paperlog,papClass where paperlog.cPapcType=papClass.cPapcType and paperlog.iyear=2012 and paperlog.imonth=7 and papClass.cPapcName='入库' group by cDepotId,cProdId) inPaperlog on invent.cProdId=inPaperlog.cProdid and invent.cDepotId=inPaperlog.cDepotId left join ( select cDepotId,paperlog.cProdId,sum(iQuanTity)ou_iQuanTity,sum(iSuCentiare)ou_iSuCentiare from paperlog,papClass where paperlog.cPapcType=papClass.cPapcType and paperlog.iyear=2012 and paperlog.imonth=7 and papClass.cPapcName='出库' group by cDepotId,cProdId )ouPaperlog on invent.cProdId=ouPaperlog.cProdId and invent.cDepotId=ouPaperlog.cDepotId where in_iQuantity<>0 or in_iSuCentiare<>0 or in_iSuAmt<>0 or ou_iQuanTity<>0 or ou_iSuCentiare<>0 order by invent.cprodid,invent.cDepotId
--try select invent.cDepotId,invent.cprodid ,case when in_iQuantity is null then 0 else in_iQuantity end in_iQuantity ,case when in_iSuCentiare is null then 0 else in_iSuCentiare end in_iSuCentiare ,case when in_iSuAmt is null then 0 else in_iSuAmt end in_iSuAmt ,case when ou_iQuanTity is null then 0 else ou_iQuanTity end ou_iQuanTity ,case when ou_iSuCentiare is null then 0 else ou_iSuCentiare end ou_iSuCentiare from ( select depot.cDepotId,cDepotName,invent.cClassId,cProdid,cProdName,iCentiare,cSpecif,cUnit from invent FULL OUTER JOIN depot on invent.cProdid<>depot.cDepotId )invent left join ( select cDepotId,paperlog.cProdId, sum(case when papClass.cPapcName = '入库' then iQuanTity else null end) as in_iQuanTity, sum(case when papClass.cPapcName = '入库' then iSuCentiare else null end) as iSuCentiare, sum(case when papClass.cPapcName = '入库' then iSuAmt else null end) as iSuAmt, sum(case when papClass.cPapcName = '出库' then iQuanTity else null end) as ou_iQuanTity, sum(case when papClass.cPapcName = '出库' then iSuCentiare else null end) as ou_iSuCentiare from paperlog,papClass where paperlog.cPapcType=papClass.cPapcType and paperlog.iyear=2012 and paperlog.imonth=7 group by cDepotId,cProdId ) Paperlog on invent.cProdId=Paperlog.cProdid and invent.cDepotId=Paperlog.cDepotId where in_iQuantity<>0 or in_iSuCentiare<>0 or in_iSuAmt<>0 or ou_iQuanTity<>0 or ou_iSuCentiare<>0 order by invent.cprodid,invent.cDepotId
------解决方案--------------------