以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]分组统计代码出错(已解决)  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=64952)

--  作者:yyzlxc
--  发布时间:2015/3/5 20:29:00
--  [求助]分组统计代码出错(已解决)
在原案例的基础上增加一列期初库存统计列,但是不知何故,日期条件的代码加入加入后出错,请各位老师指教,谢谢!!


Forms("统计").Open()
Dim et As Date = Forms("统计").Controls("ETime1").value
Dim st As Date = Forms("统计").Controls("STime1").value
Dim str As String = Format(st,"yyyy-MM-dd") & "---" & Format(et,"yyyy-MM-dd")
Dim b As New SQLGroupTableBuilder("统计表1","例子")
b.Groups.AddDef("产品")
b.Totals.AddDef("入库", "入库", str & "_入库")
b.Totals.AddDef("出库", "出库", str & "_出库")
b.Totals.AddDef("库存", "库存", str & "_截止库存")
b.Totals.AddExp("期初库存","入库",""& str &"_期初库存")
\'b.filter = "日期 >= \'"& st &"\' And 日期 <= \'"& et &"\'"
b.Build
Tables("统计表1").Cols("期初库存").Move(1)
For Each cp As String In DataTables("例子").GetValues("产品", "产品 not in (\'"& DataTables("统计表1").GetComboListString("产品").Replace("|", "\',\'") & "\')")
    Dim nr As Row = Tables("统计表1").AddNew
    nr("产品") = cp
Next
For Each r As Row In Tables("统计表1").Rows
    Dim filter = " 日期 <= \'"& et &"\'and 产品 = \'" & r("产品") & "\'"
    Dim kc As Double = DataTables("例子").Compute("sum(入库)",filter) - DataTables("例子").Compute("sum(出库)",filter)
    r("库存") = kc
    r("期初库存") = kc + r("出库") - r("入库")
Next
MainTable = Tables("统计表1")
Tables("统计表1").AutoSizeCols()
DataTables("统计表1").Save()

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:例子.foxdb


[此贴子已经被作者于2015/3/5 20:51:15编辑过]

--  作者:有点甜
--  发布时间:2015/3/5 20:32:00
--  
Forms("统计").Open()
Dim et As Date = Forms("统计").Controls("ETime1").value
Dim st As Date = Forms("统计").Controls("STime1").value
Dim str As String = Format(st,"yyyy-MM-dd") & "---" & Format(et,"yyyy-MM-dd")
Dim b As New SQLGroupTableBuilder("统计表1","例子")
b.Groups.AddDef("产品")
b.Totals.AddDef("入库", "入库", str & "_入库")
b.Totals.AddDef("出库", "出库", str & "_出库")
b.Totals.AddDef("库存", "库存", str & "_截止库存")
b.Totals.AddExp("期初库存","入库",""& str &"_期初库存")
b.filter = "日期 >= #" & st &"# And 日期 <= #"& et &"#"
b.Build
Tables("统计表1").Cols("期初库存").Move(1)
For Each cp As String In DataTables("例子").GetValues("产品", "产品 not in (\'"& DataTables("统计表1").GetComboListString("产品").Replace("|", "\',\'") & "\')")
    Dim nr As Row = Tables("统计表1").AddNew
    nr("产品") = cp
Next
For Each r As Row In Tables("统计表1").Rows
    Dim filter = " 日期 <= #"& et &"# and 产品 = \'" & r("产品") & "\'"
    Dim kc As Double = DataTables("例子").Compute("sum(入库)",filter) - DataTables("例子").Compute("sum(出库)",filter)
    r("库存") = kc
    r("期初库存") = kc + r("出库") - r("入库")
Next
MainTable = Tables("统计表1")
Tables("统计表1").AutoSizeCols()
DataTables("统计表1").Save()

--  作者:yyzlxc
--  发布时间:2015/3/5 20:47:00
--  
谢谢甜老师的指教,但是不明白为什么要加“#”号,上面按钮的同样的代码是分号,难道是因为SQLGroupTableBuilder的缘故吗?还请甜老师指教,谢谢!!
--  作者:有点甜
--  发布时间:2015/3/5 20:48:00
--  
 日期列的就是要用#号的
--  作者:yyzlxc
--  发布时间:2015/3/5 20:51:00
--  
知道了,谢谢甜老师!!
--  作者:狐狸爸爸
--  发布时间:2015/3/6 8:46:00
--  

也不一定,如果Sql server的数据源话,要单引号:

 

http://www.foxtable.com/help/topics/2343.htm

http://www.foxtable.com/help/topics/2401.htm