日期:2014-05-18 浏览次数:20468 次
SELECT distinct dbo.Customer.cCusAbbName AS 客户简称, dbo.SO_SOMain.cSOCode AS 订单号,dbo.SO_SOMain.dDate AS 订单日期, dbo.Person.cPersonName AS 业务员, dbo.Inventory.cInvCode AS 存货编码,dbo.Inventory.cInvName AS 存货名称, dbo.Inventory.cInvStd AS 规格型号,dbo.SO_SODetails.iQuantity AS 数量,dbo.ComputationUnit.cComUnitName AS 主计量, dbo.SO_SODetails.iTaxUnitPrice AS 含税单价,dbo.SO_SODetails.iSum AS 价税合计, ISNULL(dbo.SO_SODetails.foutquantity, 0) AS 出库数量, (case when isnull(sum(distinct RdRecords.iQuantity),0)=0 then isnull(sum(distinct RdRecords.iQuantity),0)+ISNULL(dbo.SO_SODetails.foutquantity, 0) else isnull(sum(distinct RdRecords.iQuantity),0) end) as 累计入库数量, MAX(dbo.RdRecord.dDate) AS 入库最后日期,dbo.SO_SODetails.dPreDate AS 预发货日期, MAX(dbo.DispatchList.dDate) AS 最后发货日期, dbo.SO_SODetails.iFHQuantity AS 累计发货数量,dbo.SO_SOMain.cCusOAddress AS 发货地址, dbo.SO_SODetails.fretquantity AS 累计退货数量, dbo.SO_SODetails.iKPQuantity AS 累计开票数量,dbo.SO_SODetails.iKPMoney AS 累计开票金额, ISNULL(dbo.SO_SODetails.imoneysum, 0) AS 累计收款,ISNULL(dbo.SO_SODetails.iexchsum, 0) AS 累计收款原币, dbo.SO_SOMain.cMaker AS 制单人,dbo.SO_SOMain.cVerifier AS 审核人,dbo.SO_SOMain.cCloser AS 关闭人, dbo.SO_SODetails.cSCloser AS 行关闭人 FROM dbo.SO_SODetails right outer join dbo.Inventory on dbo.Inventory.cInvCode = dbo.SO_SODetails.cInvCode left outer join dbo.ComputationUnit on dbo.Inventory.cComUnitCode = dbo.ComputationUnit.cComunitCode on dbo.SO_SODetails.cUnitID = ComputationUnit.cComunitCode right outer join dbo.so_somain on dbo.so_somain.csocode=dbo.so_sodetails.csocode left outer join dbo.Person ON dbo.Person.cPersonCode=dbo.SO_SOMain.cPersonCode on dbo.SO_SODetails.ID = dbo.SO_SOMain.ID right outer join dbo.Customer on dbo.Customer.cCusCode = dbo.SO_SOMain.cCusCode left outer join dbo.RdRecord ON dbo.SO_SODetails.cSOCode = dbo.RdRecord.cDefine10 RIGHT OUTER JOIN dbo.RdRecords ON dbo.RdRecord.ID = dbo.RdRecords.ID AND dbo.SO_SODetails.cInvCode = dbo.RdRecords.cInvCode on dbo.SO_SOMain.cSOCode = dbo.RdRecord.cDefine10 LEFT OUTER JOIN dbo.DispatchList ON dbo.DispatchList.cSOCode = dbo.RdRecord.cDefine10 group by dbo.Customer.cCusAbbName,dbo.SO_SOMain.cSOCode,dbo.SO_SOMain.dDate,dbo.Person.cPersonName,dbo.Inventory.cInvCode, dbo.Inventory.cInvName,dbo.Inventory.cInvStd,dbo.SO_SODetails.iQuantity,dbo.ComputationUnit.cComUnitName,dbo.SO_SODetails.iTaxUnitPrice, dbo.SO_SODetails.iSum,dbo.SO_SODetails.foutquantity,dbo.SO_SODetails.dPreDate,dbo.SO_SODetails.iFHQuantity,dbo.SO_SOMain.cCusOAddress, dbo.SO_SODetails.fretquantity,dbo.SO_SODetails.iKPQuantity,dbo.SO_SODetails.iKPMoney,dbo.SO_SODetails.imoneysum,dbo.SO_SODetails.iexchsum, dbo.SO_SOMain.cMaker,dbo.SO_SOMain.cVerifier,dbo.SO_SOMain.cCloser,dbo.SO_SODetails.cSCloser