Tables(e.form.Name & "_Table1").fill("select 加工商编码,加工商名称,简码,分类名称,期初金额,付款金额,借支金额,加工费金额, (case when 余额=0 then null else 余额 end) as 余额 from (select a.加工商编码,a.加工商名称,a.简码,a.分类名称,期初金额,sum(金额2) as 付款金额,sum(金额3) as 借支金额, sum(金额1) as 加工费金额,(isnull(期初金额,0)+isnull(sum(金额2),0)+isnull(sum(金额3),0)-isnull(sum(金额1),0)) as 余额 from {加工商} as a left join (selec 单位编码, 单位名称, 0 as 金额1, 贷方金额 as 金额2,0 as 金额3 from {资金收付明细单} where 单据状态='已审核' and 单据性质='付加工费' union all selec 单位编码, 单位名称, 0,0, 贷方金额 as 金额3 from {资金收付明细单} where 单据状态='已审核' and 单据性质='加工商借支' union all Selec 加工商编码, 加工商名称,金额,0,0 from {加工收发明细} where 单据状态='已审核') As b on a.加工商编码 = b.单位编码 And a.加工商名称 = b.单位名称 group by a.加工商编码, a.加工商名称,a.简码,a.分类名称,期初金额) as c","wjhansdata",True)
|