declare @table table(DDID INT,FHDID INT ,CKDID INT,ZGYSDID INT,CWYSDID INT)--定义表变量来存放存储过程返回的内容
insert into @table EXEC proc_xsddgz_lj --将存储过程执行的结果放入表变量中
SELECT b.FSETTLECURRID,b.FMATERIALID,b.FQTY,b.FBILLNO,b.FBILLTYPEID,b.FSEQ,b.FTAXPRICE,b.FDELIVERYDATE,b.FCREATEDATE,b.FPLANDELIVERYDATE,
b.FCUSTID,b.FSALERID,
a.ddid ,b.FQTY ddsl,a.FHDID,c.FQTY fhdsl,a.CKDID,d.FREALQTY ckdsl,
a.ZGYSDID,zg.FPRICEQTY zgsl,a.CWYSDID,cw.FPRICEQTY cwsl,cw.FALLAMOUNTFOR cwje FROM @table a
--销售订单
INNER JOIN (SELECT sof.FSETTLECURRID,soe.FMATERIALID,soe.FQTY,soe.FENTRYID,
so.FBILLNO,so.FBILLTYPEID,soe.FSEQ,soef.FTAXPRICE,so.FCUSTID,so.FSALERID,
soed.FDELIVERYDATE,so.FCREATEDATE ,soe.FPLANDELIVERYDATE FROM T_SAL_ORDER so
INNER JOIN T_SAL_ORDERENTRY soe ON so.FID = soe.FID
INNER JOIN T_SAL_ORDERFIN sof ON soe.FENTRYID = sof.FENTRYID
INNER JOIN T_SAL_ORDERENTRY_D soed ON soe.FENTRYID = soed.FENTRYID
INNER JOIN T_SAL_ORDERENTRY_F soef ON soe.FENTRYID = soef.FENTRYID)b
ON a.DDID = b.FENTRYID
--发货通知单
LEFT JOIN T_SAL_DELIVERYNOTICEENTRY c ON a.FHDID = c.FENTRYID
--销售出库单
LEFT JOIN T_SAL_OUTSTOCKENTRY d ON a.CKDID = d.FENTRYID
--暂估应收
LEFT JOIN (SELECT are.FPRICEQTY,are.FENTRYID FROM T_AR_RECEIVABLE ar INNER JOIN T_AR_RECEIVABLEENTRY are ON ar.FID=are.FID
WHERE ar.FSETACCOUNTTYPE=2 AND ar.FDOCUMENTSTATUS = 'C' )zg ON a.ZGYSDID=zg.FENTRYID
--财务应收
LEFT JOIN (SELECT are.FPRICEQTY,are.FENTRYID,are.FALLAMOUNTFOR FROM T_AR_RECEIVABLE ar INNER JOIN T_AR_RECEIVABLEENTRY are ON ar.FID=are.FID
WHERE ar.FSETACCOUNTTYPE=3 AND ar.FDOCUMENTSTATUS = 'C' )cw ON a.CWYSDID=cw.FENTRYID