以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 组合统计 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=192699) |
-- 作者:g1j2h3 -- 发布时间:2024/7/14 17:47:00 -- 组合统计 麻烦老师看下边代码错在哪里,错误提示:找不到列 类别,换用取消注释的代码没问题 Selec t Case e.Path Case "kcb.htm" \' Dim cmd As New SQLCommand \' Dim cpxx As DataTable \' Dim rkmx As DataTable \' Dim ckmx As DataTable \' cmd.C \' cmd.CommandText = "Select 类别,库存编码,产品名称,规格,单位,商标,备注,期初库存 F ROM {产品信息}" \' cpxx = cmd.ExecuteReader() \' Dim bd1 As New GroupTableBuilder("统计表1", cpxx) Dim cpxx As String = "Select 类别,库存编码,产品名称,规格,单位,商标,备注,期初库存 F ROM {产品信息}" Dim bd1 As New GroupTableBuilder("统计表1", cpxx, "sale") Dim dt1 As fxDataSource bd1.Groups.AddDef("类别") bd1.Groups.AddDef("库存编码") \'根据型号分组 bd1.Groups.AddDef("产品名称") bd1.Groups.AddDef("规格") bd1.Groups.AddDef("单位") bd1.Groups.AddDef("商标") bd1.Groups.AddDef("备注") bd1.Totals.AddDef("期初库存", "期初库存数量") \'对数量进行统计 dt1 = bd1.BuildDataSource() \' cmd.CommandText = "Select 类别,库存编码,产品名称,规格,单位,商标,备注,入库数量 F ROM {入库明细} " \' rkmx = cmd.ExecuteReader() \' Dim bd2 As New GroupTableBuilder("统计表2", rkmx) Dim rkmx As String = "Select 类别,库存编码,产品名称,规格,单位,商标,备注,入库数量 F ROM {入库明细}" Dim bd2 As New GroupTableBuilder("统计表2", rkmx, "sale") Dim dt2 As fxDataSource bd2.Groups.AddDef("类别") bd2.Groups.AddDef("库存编码") \'根据型号分组 bd2.Groups.AddDef("产品名称") bd2.Groups.AddDef("规格") bd2.Groups.AddDef("单位") bd2.Groups.AddDef("商标") bd2.Groups.AddDef("备注") bd2.Totals.AddDef("入库数量", "入库数量") \'对数量进行统计 dt2 = bd2.BuildDataSource() \' cmd.CommandText = "Select 类别,库存编码,产品名称,规格,单位,商标,备注,出库数量 F ROM {出库明细} " \' ckmx = cmd.ExecuteReader() \' Dim bd3 As New GroupTableBuilder("统计表3", ckmx) Dim ckmx As String = "Select 类别,库存编码,产品名称,规格,单位,商标,备注,出库数量 F ROM {出库明细}" Dim bd3 As New GroupTableBuilder("统计表3", ckmx, "sale") Dim dt3 As fxDataSource bd3.Groups.AddDef("类别") bd3.Groups.AddDef("库存编码") \'根据型号分组 bd3.Groups.AddDef("产品名称") bd3.Groups.AddDef("规格") bd3.Groups.AddDef("单位") bd3.Groups.AddDef("商标") bd3.Groups.AddDef("备注") bd3.Totals.AddDef("出库数量", "出库数量") \'对数量进行统计 dt3 = bd3.BuildDataSource() Dim nms As String() = { "库存编码", "产品名称", "规格", "单位", "商标", "备注"} dt1.Combine(nms, dt2, nms) dt1.Combine(nms, dt3, nms) \'将退货统计数据组合到进货统计数据 dt1.Show("当前库存") \'显示统计结果 MainTable = Tables("当前库存") msgbox(123) With DataTables("当前库存").DataCols \'用表达式列计算库存数据 .Add("库存数量", GetType(Integer), "IsNull([期初库存数量],0) + IsNull([入库数量],0) - ISNULL([出库数量],0)") End With msgbox(456) End Selec t [此贴子已经被作者于2024/7/14 17:59:44编辑过]
|
-- 作者:有点蓝 -- 发布时间:2024/7/14 20:23:00 -- 试试 Dim nms As String() = {"类别", "库存编码", "产品名称", "规格", "单位", "商标", "备注"}
|
-- 作者:g1j2h3 -- 发布时间:2024/7/14 21:29:00 -- 试了,还是不行 |
-- 作者:有点蓝 -- 发布时间:2024/7/14 21:42:00 -- 那要提供实例测试才知道什么问题了。 |
-- 作者:g1j2h3 -- 发布时间:2024/7/14 22:00:00 -- 除了上述方法还有没有其他方法从数据源sale中组合统计产品信息,入库明细和出库明细中的数据 |
-- 作者:有点蓝 -- 发布时间:2024/7/14 22:46:00 -- 其实就使用注释的代码,也就是SQLCommand,效果是一样的呀。 或者纯sql,大概 Select a.类别,a.库存编码,a.产品名称,a.规格,a.单位,a.商标,a.备注,sum(期初库存) as 期初库存数量,sum(入库数量) as 入库数量,sum(出库数量) as 出库数量 F ROM {产品信息} as a inner join {入库明细} as b on a.类别=b.类别 and a.库存编码=b.库存编码 and ....... inner join {出库明细} as c on a.类别=c.类别 and a.库存编码=c.库存编码 and ....... group by a.类别,a.库存编码,a.产品名称,a.规格,a.单位,a.商标,a.备注
|