以文本方式查看主题
- Foxtable(狐表) (http://foxtable.net/bbs/index.asp)
-- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2)
---- 求应付款总账 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=101532)
|
-- 作者:yjf123
-- 发布时间:2017/6/2 11:06:00
-- 求应付款总账
求应付款总账,如图,怎么建查询表,得到应付款总账表? 此主题相关图片如下:qq截图20170602105818.jpg
|
-- 作者:有点色
-- 发布时间:2017/6/2 11:32:00
--
Dim sd As Date = "2017-03-01" Dim ed As Date = "2017-03-31"
Dim filter1 As String = "发生日期 < #" & sd & "#" Dim filter2 As String = "发生日期 >= #" & sd & "# and 发生日期 <= #" & ed & "#" Dim sql As String = "Select a.往来单位编号, 期初应付, 本期增加应付, 本期减少应付, 期初应付+本期增加应付-本期减少应付 As 期末结存 from (Select 往来单位编号, (iif(sum(应付金额) is null,0,sum(应付金额)) - iif(sum(已付金额) is null,0,sum(已付金额))) As 期初应付 from {应付单} where " & filter1 & " group by 往来单位编号) As a left join (Select 往来单位编号, iif(sum(应付金额) is null, 0, sum(应付金额)) As 本期增加应付, iif(sum(已付金额) is null, 0, sum(应付金额)) As 本期减少应付 from {应付单} where " & filter2 & " group by 往来单位编号) As b on a.往来单位编号=b.往来单位编号"
Dim q As new QueryBuilder q.TableName = "查询" q.SelectString = sql q.Build MainTable = Tables("查询")
|
-- 作者:yjf123
-- 发布时间:2017/6/2 11:57:00
--
不对呀,换1月份查询看看
|
-- 作者:有点色
-- 发布时间:2017/6/2 12:34:00
--
Dim sd As Date = "2017-03-01" Dim ed As Date = "2017-03-31"
Dim filter1 As String = "发生日期 < #" & sd & "#" Dim filter2 As String = "发生日期 >= #" & sd & "# and 发生日期 <= #" & ed & "#" Dim sql As String = "select c.往来单位编号, 期初应付, 本期增加应付, 本期减少应付, 期初应付+本期增加应付-本期减少应付 As 期末结存 from (select a.往来单位编号, 期初应付 from (select 往来单位编号 from {应付单} group by 往来单位编号) as a left join (Select 往来单位编号, (iif(sum(应付金额) is null,0,sum(应付金额)) - iif(sum(已付金额) is null,0,sum(已付金额))) As 期初应付 from {应付单} where " & filter1 & " group by 往来单位编号) As b on a.往来单位编号 = b.往来单位编号) As c left join (Select 往来单位编号, iif(sum(应付金额) Is null, 0, sum(应付金额)) As 本期增加应付, iif(sum(已付金额) Is null, 0, sum(应付金额)) As 本期减少应付 from {应付单} where " & filter2 & " group by 往来单位编号) As d on c.往来单位编号 = d.往来单位编号" Dim q As new QueryBuilder q.TableName = "查询" q.SelectString = sql q.Build MainTable = Tables("查询")
|
-- 作者:yjf123
-- 发布时间:2017/6/2 13:18:00
--
怎么加上”往来单位名称“
[此贴子已经被作者于2017/6/2 13:18:34编辑过]
|
-- 作者:yjf123
-- 发布时间:2017/6/2 13:52:00
--
fill外部表就不行了
|
-- 作者:有点色
-- 发布时间:2017/6/2 14:09:00
--
测试没问题。你的是什么数据源?
Dim sd As Date = "2017-03-01" Dim ed As Date = "2017-03-31"
Dim filter1 As String = "发生日期 < #" & sd & "#" Dim filter2 As String = "发生日期 >= #" & sd & "# and 发生日期 <= #" & ed & "#" Dim sql As String = "select c.往来单位编号, 期初应付, 本期增加应付, 本期减少应付, 期初应付+本期增加应付-本期减少应付 As 期末结存 from (select a.往来单位编号, 期初应付 from (select 往来单位编号 from {应付单} group by 往来单位编号) as a left join (Select 往来单位编号, (iif(sum(应付金额) is null,0,sum(应付金额)) - iif(sum(已付金额) is null,0,sum(已付金额))) As 期初应付 from {应付单} where " & filter1 & " group by 往来单位编号) As b on a.往来单位编号 = b.往来单位编号) As c left join (Select 往来单位编号, iif(sum(应付金额) Is null, 0, sum(应付金额)) As 本期增加应付, iif(sum(已付金额) Is null, 0, sum(应付金额)) As 本期减少应付 from {应付单} where " & filter2 & " group by 往来单位编号) As d on c.往来单位编号 = d.往来单位编号"
DataTables("表A").Fill(sql, True)
|
-- 作者:yjf123
-- 发布时间:2017/6/2 14:11:00
--
sql 日期的换 \' 了,还是不行,要把iif去掉
|
-- 作者:yjf123
-- 发布时间:2017/6/2 14:21:00
--
1.怎么加上”往来单位名称“
2.sql数据源,iif判断会出错,去掉iif的话,数据有不正确
[此贴子已经被作者于2017/6/2 14:47:47编辑过]
|
-- 作者:有点色
-- 发布时间:2017/6/2 15:00:00
--
以下是引用yjf123在2017/6/2 14:11:00的发言: sql 日期的换 \' 了,还是不行,要把iif去掉
sqlserver数据库的话,用isnull函数代替iif函数
|