Forms("查询").open
Dim sql As String = "Select 项目,金额,期间,收入明细,部门编号 FROM {门诊收入预算} where (收入明细 not like '总计' or 收入明细 is null) and (收入明细 not like '%合计%' or 收入明细 is null) and 项目 is not null union all Select 项目,金额,'小计',收入明细,部门编号 FROM {门诊收入预算} where (收入明细 not like '总计' or 收入明细 is null) and (收入明细 not like '%合计%' or 收入明细 is null) and 项目 is not null "
Dim b As New CrossTableBuilder("统计表1",sql)
b.HGroups.AddDef("项目")
b.vGroups.AddDef("部门编号")
b.VGroups.AddDef("期间","{0}月")
b.Totals.AddDef("金额")
b.HorizontalTotal = True
b.VerticalTotal = True
b.Build()
For Each dr As DataRow In DataTables("统计表1").DataRows
Dim sum As Double = 0
For Each c As DataCol In DataTables("统计表1").DataCols
If c.Caption Like "*小计*" Then sum += dr(c.Name)
Next
dr("合计") = sum
Next
Forms("查询").controls("table1").Table.DataSource = DataTables("统计表1")