Di m sq lstr a s S tring="s elect * f rom (s elect distinct [订单编号],[车队] a s 往来单位,'拖车费' a s 收费科目,[拖车费] a s 单价, c ount(*) a s 数量,sum(拖车费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001'and [拖车费]>0 g roup by [订单编号], [车队],[拖车费]) a s a " & _
" u nion s elect * f rom (s elect distinct [订单编号],[承运方] a s 往来单位,'铁路运费' a s 收费科目,[铁路运费] a s 单价, c ount(*) a s 数量,sum(铁路运费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [铁路运费]>0 g roup by [订单编号], [承运方],[铁路运费]) a s b " & _
" u nion s elect * f rom (s elect distinct [订单编号],[报关行] a s 往来单位,'报关费' a s 收费科目,[报关费] a s 单价, c ount(*) a s 数量,sum(报关费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [报关费]>0 g roup by [订单编号], [报关行],[报关费]) a s c " & _
" u nion s elect * f rom (s elect distinct [订单编号],[装箱货场] a s 往来单位,'装箱费' a s 收费科目,[装箱费] a s 单价, c ount(*) a s 数量,sum(装箱费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [装箱费]>0 g roup by [订单编号], [装箱货场],[装箱费]) a s d " & _
" u nion s elect * f rom (s elect distinct [订单编号],[加固队] a s 往来单位,'加固费' a s 收费科目,[加固费] a s 单价, c ount(*) a s 数量,sum(加固费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [加固费]>0 g roup by [订单编号], [加固队],[加固费]) a s e " & _
" u nion s elect * f rom (s elect distinct [订单编号],[代码公司] a s 往来单位,'境外运费USD' a s 收费科目,[境外运费USD] a s 单价, c ount(*) a s 数量,sum(境外运费USD) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [境外运费USD]>0 g roup by [订单编号], [代码公司],[境外运费USD]) a s f" & _
" u nion s elect * f rom (s elect distinct [订单编号],[单证公司] a s 往来单位,'单证' a s 收费科目,[单证公司] a s 单价, c ount(*) a s 数量,sum(单证费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [单证费]>0 g roup by [订单编号], [单证公司],[单证费]) a s g" & _
" u nion s elect * f rom (s elect distinct [订单编号],[口岸代理] a s 往来单位,'查验费' a s 收费科目,[查验费] a s 单价, c ount(*) a s 数量,sum(查验费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [查验费]>0 g roup by [订单编号], [口岸代理],[查验费]) a s h" & _
" u nion s elect * f rom (s elect distinct [订单编号],[口岸代理] a s 往来单位,'滞留费' a s 收费科目,[滞留费] a s 单价, c ount(*) a s 数量,sum(滞留费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [滞留费]>0 g roup by [订单编号], [口岸代理],[滞留费]) a s i" & _
" u nion s elect * f rom (s elect distinct [订单编号],[口岸代理] a s 往来单位,'放射放行费' a s 收费科目,[放射放行费] a s 单价, c ount(*) a s 数量,sum(放射放行费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [放射放行费]>0 g roup by [订单编号], [口岸代理],[放射放行费]) a s j" & _
" u nion s elect * f rom (s elect distinct [订单编号],[口岸代理] a s 往来单位,'退运运费' a s 收费科目,[退运运费] a s 单价, c ount(*) a s 数量,sum(退运运费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [退运运费]>0 g roup by [订单编号], [口岸代理],[退运运费]) a s k" & _
" u nion s elect * f rom (s elect distinct [订单编号],[口岸代理] a s 往来单位,'落地交付费' a s 收费科目,[落地交付费] a s 单价, c ount(*) a s 数量,sum(落地交付费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [落地交付费]>0 g roup by [订单编号], [口岸代理],[落地交付费]) a s l" & _
" u nion s elect * f rom (s elect distinct [订单编号],[其他单位] a s 往来单位,'RMB杂费' a s 收费科目,[RMB杂费] a s 单价, c ount(*) a s 数量,sum(RMB杂费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [RMB杂费]>0 g roup by [订单编号], [其他单位],[RMB杂费]) a s m" & _
" u nion s elect * f rom (s elect distinct [订单编号],[其他单位1] a s 往来单位,'美元杂费' a s 收费科目,[美元杂费] a s 单价, c ount(*) a s 数量,sum(美元杂费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [美元杂费]>0 g roup by [订单编号], [其他单位1],[美元杂费]) a s n" & _
" u nion s elect * f rom (s elect distinct [订单编号],[卖箱公司] a s 往来单位,'买箱费' a s 收费科目,[买箱费] a s 单价, c ount(*) a s 数量,sum(买箱费) a s 金额 f rom {销售应付} w here [订单编号]='TW-202012-001' and [买箱费]>0 g roup by [订单编号], [卖箱公司],[买箱费]) a s o"
Di m Bo ok a s Ne w XL S.Book(ProjectPath & "Attachments\单piao收支模板.xls")
Di m fl a s St ring = Proj ectPath & "Reports\单piao收支模板.xls"
'bo ok.Ad d Da taTable("销售明细","天津拓帷",sqlstr) '添加父表
bo ok.Ad d D ataTable("销售应付","天津拓帷",sqlstr) '添加子表
'bo ok.Ad d Relati on("销售明细","订单编号","销售应付","订单编号") '建立关联
Boo k. Bu ild() '生成细节区
Boo k. S ave(fl) '保存工作簿
Di m Pr oc a s Ne w P rocess '打开工作簿
Pro c.File = fl
Pro c.Start()