以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  多表时间段数据查询或统计如何做?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=32339)

--  作者:zerov
--  发布时间:2013/4/29 22:58:00
--  多表时间段数据查询或统计如何做?
三个表,《剩余资金》=《回款》-《费用》,窗口中有2个DateTimePicker,分别为“起始日”和“截止日”控件,如果控件值为空,则统计所有日期的回款和费用,得出剩余资金。如果起始日”和“截止日”设定了日期,则按设置的日期期间分别统计所有分公司的回款与费用,并得出剩余资金。
不设日期的统计代码如下,怎样加入日期段的筛选fiter?
1、回款

图片点击可在新窗口打开查看此主题相关图片如下:hk.png
图片点击可在新窗口打开查看
2、费用

图片点击可在新窗口打开查看此主题相关图片如下:fy.png
图片点击可在新窗口打开查看
3、最终效果
图片点击可在新窗口打开查看此主题相关图片如下:1111.png
图片点击可在新窗口打开查看

--  作者:zerov
--  发布时间:2013/4/29 23:02:00
--  
这是表中datachanged的代码,但每个分公司得一个一个设置日期时间段,如果要在窗口改成统一的时间段,如何弄:

Select e.DataCol.Name
    Case "分公司","期间_起始日","期间_截止日"
        If e.DataRow.IsNull("分公司") = False AndAlso e.DataRow.IsNull("期间_起始日") = False AndAlso e.DataRow.IsNull("期间_截止日") = False Then
            e.DataRow("回款_其它老") = DataTables("回款").Compute("sum(回款金额)","分公司=\'" & e.DataRow("分公司") & "\' and 日期 > #" & e.DataRow("期间_起始日") & "# and 日期 < #" & e.DataRow("期间_截止日") & "# and 收款方式 <> \'承兑\' and 类型 = \'老\'")
            e.DataRow("回款_其它新") = DataTables("回款").Compute("sum(回款金额)","分公司=\'" & e.DataRow("分公司") & "\' and 日期 > #" & e.DataRow("期间_起始日") & "# and 日期 < #" & e.DataRow("期间_截止日") & "# and 收款方式 <> \'承兑\' and 类型 = \'新\'")
            e.DataRow("回款_承兑老") = DataTables("回款").Compute("sum(回款金额)","分公司=\'" & e.DataRow("分公司") & "\' and 日期 > #" & e.DataRow("期间_起始日") & "# and 日期 < #" & e.DataRow("期间_截止日") & "# and 收款方式 = \'承兑\' and 类型 = \'老\'")
            e.DataRow("回款_承兑新") = DataTables("回款").Compute("sum(回款金额)","分公司=\'" & e.DataRow("分公司") & "\' and 日期 > #" & e.DataRow("期间_起始日") & "# and 日期 < #" & e.DataRow("期间_截止日") & "# and 收款方式 = \'承兑\' and 类型 = \'新\'")
            e.DataRow("回款_小计") = e.DataRow("回款_其它老") + e.DataRow("回款_其它新") + e.DataRow("回款_承兑老") + e.DataRow("回款_承兑新")
            e.DataRow("费用_经理往来") = DataTables("费用").Compute("sum(支出金额)","分公司=\'" & e.DataRow("分公司") & "\' and 日期 > #" & e.DataRow("期间_起始日") & "# and 日期 < #" & e.DataRow("期间_截止日") & "# and 费用类型 = \'经理借款\'")
            e.DataRow("费用_劳务支付") = DataTables("费用").Compute("sum(支出金额)","分公司=\'" & e.DataRow("分公司") & "\' and 日期 > #" & e.DataRow("期间_起始日") & "# and 日期 < #" & e.DataRow("期间_截止日") & "# and 费用类型 = \'劳务往来\'")
            e.DataRow("费用_内部往来") = DataTables("费用").Compute("sum(支出金额)","分公司=\'" & e.DataRow("分公司") & "\' and 日期 > #" & e.DataRow("期间_起始日") & "# and 日期 < #" & e.DataRow("期间_截止日") & "# and 费用类型 = \'内部往来\'")
            e.DataRow("费用_小计") = e.DataRow("费用_经理往来") + e.DataRow("费用_劳务支付") + e.DataRow("费用_内部往来")
            e.DataRow("剩余可支配金额") = e.DataRow("回款_小计") - e.DataRow("费用_小计")
            e.DataRow("备注") = Nothing
        Else
            e.DataRow("回款_其它老") = Nothing
            e.DataRow("回款_其它新") = Nothing
            e.DataRow("回款_承兑老") = Nothing
            e.DataRow("回款_承兑新") = Nothing
            e.DataRow("回款_小计") = Nothing
            e.DataRow("费用_经理往来") = Nothing
            e.DataRow("费用_劳务支付") = Nothing
            e.DataRow("费用_内部往来") = Nothing
            e.DataRow("费用_小计") = Nothing
            e.DataRow("剩余可支配金额") = Nothing
            e.DataRow("备注") = Nothing
        End If
End Select

--  作者:zerov
--  发布时间:2013/5/1 21:20:00
--  
有大师回家了没?
--  作者:sloyy
--  发布时间:2013/5/1 22:12:00
--  
有测试数据吗?我来试试
--  作者:sloyy
--  发布时间:2013/5/1 23:44:00
--  

查询表:剩余资金SQL语句

select {回款}.分公司,sum(iif(类型=\'新\' and 收款方式<>\'承兑\' ,回款金额,0)) As  回款_其他新,sum(iif(类型=\'旧\' and 收款方式<>\'承兑\' ,回款金额,0)) As  回款_其他旧,sum(iif(类型=\'新\' and 收款方式=\'承兑\' ,回款金额,0)) As  回款_承兑新,sum(iif(类型=\'旧\' and 收款方式=\'承兑\' ,回款金额,0)) As  回款_承兑旧, sum(回款金额) As 回款_小计, sum(iif({费用}.费用类型=\'经理往来\',支出金额,0)) As  费用_经理往来, sum(iif({费用}.费用类型=\'劳务支付\',支出金额,0)) As  费用_劳务支付,sum(iif({费用}.费用类型=\'内部往来\',支出金额,0)) As  费用_内部往来,sum(支出金额) As  费用_小计,(sum(回款金额)-sum(支出金额)) as 剩余资金 from {回款} INNER JOIN {费用}  on {回款}.分公司 = {费用}.分公司   where {回款}.日期 BETWEEN #起始日# and #截止日# GrouP by {回款}.分公司