主题:急!!大虾帮我看一下SQL语句!!
stx:='select fl.日期,fl.客户编号,kh.cCusName as 客户名称,fl.单据类型,fl.单据号,fl.业务员编号,ps.cPersonName as 业务员,fl. 应收,fl. 收回 from ( ';
stx:=stx+' select b.dDate as 日期,b.cCusCode as 客户编号,'+'''发货单'''+' as 单据类型,b.cDLcode as 单据号,b.cPersonCode as 业务员编号,c.cPersonName as 业务员,sum(a.iSum) as 应收,0 as 收回 from Dispatchlists a left join Dispatchlist b on a.DLID=b.DLID left join person c on b.cPersonCode=c.cPersonCode where b.dDate<'''+rq1+''' and '+tiaojian1+' and b.bFirst<>1 group by b.dDate,b.cCusCode,b.cBusType,b.cDLcode,b.cPersonCode,c.cPersonName ';
stx:=stx+' Union All select b.dVouchDate as 日期,a.cCusVen as 客户编号,b.cVouchType as 单据类型,b.cVouchID as 单据号,b.cPerson as 业务员编号,d.cPersonName as 业务员,0 as 应收, sum(iRAmount) as 收回 ';
stx:=stx+' from AP_CloseBills a left join AP_CloseBill b on a.iID=b.iID left join Customer c on a.cCusVen=c.cCusCode left join person d on b.cPerson=d.cPersonCode where b.dVouchDate<'''+rq1+''' and '+tiaojian2+' group by b.dVouchDate,a.cCusVen,a.iType,b.cVouchType,b.cVouchID,b.cPerson,d.cPersonName ';
stx:=stx+' ) fl left join Customer kh on fl.客户编号=kh.cCusCode left join person ps on fl.业务员编号=ps.cPersonCode group by 日期,客户编号,kh.cCusName,单据类型,单据号,fl.业务员编号,ps.cPersonName,应收,收回 order by fl. 客户编号,fl.日期';
这句里的f1 a b 从哪冒出来的,前面也没定义的
stx:=stx+' select b.dDate as 日期,b.cCusCode as 客户编号,'+'''发货单'''+' as 单据类型,b.cDLcode as 单据号,b.cPersonCode as 业务员编号,c.cPersonName as 业务员,sum(a.iSum) as 应收,0 as 收回 from Dispatchlists a left join Dispatchlist b on a.DLID=b.DLID left join person c on b.cPersonCode=c.cPersonCode where b.dDate<'''+rq1+''' and '+tiaojian1+' and b.bFirst<>1 group by b.dDate,b.cCusCode,b.cBusType,b.cDLcode,b.cPersonCode,c.cPersonName ';
stx:=stx+' Union All select b.dVouchDate as 日期,a.cCusVen as 客户编号,b.cVouchType as 单据类型,b.cVouchID as 单据号,b.cPerson as 业务员编号,d.cPersonName as 业务员,0 as 应收, sum(iRAmount) as 收回 ';
stx:=stx+' from AP_CloseBills a left join AP_CloseBill b on a.iID=b.iID left join Customer c on a.cCusVen=c.cCusCode left join person d on b.cPerson=d.cPersonCode where b.dVouchDate<'''+rq1+''' and '+tiaojian2+' group by b.dVouchDate,a.cCusVen,a.iType,b.cVouchType,b.cVouchID,b.cPerson,d.cPersonName ';
stx:=stx+' ) fl left join Customer kh on fl.客户编号=kh.cCusCode left join person ps on fl.业务员编号=ps.cPersonCode group by 日期,客户编号,kh.cCusName,单据类型,单据号,fl.业务员编号,ps.cPersonName,应收,收回 order by fl. 客户编号,fl.日期';
这句里的f1 a b 从哪冒出来的,前面也没定义的