-- SQL统计问题
Dim db As String
Dim sql As String
Dim dt As String
db="T"
If e.Form.Controls("RadioButton4").checked="True" Then
dt="date_wt"
End If
\'sql中使用了order by后,无法再重新交叉统计
If Filter > "" Then
If rb1.Checked=True Then \'按明细查询
sql = "Select 产品类别,项目名称,项目代码,委托编号,date_wt as 委托日期,桩径,委托数量,承载力*委托数量/10 as 总承载力t,小计,gcmc as 工程名称,wtunit as 委托单位,area as 区域 FRO M {zjwtsl} inner JOIN {zj} ON {zj}.wtbh = {zjwtsl}.委托编号 where "& dt &" >= \'" & date1 & "\' And "& dt &" <= \'" & date2 & "\' order by date_wt"
Tables("财务统计_Table1").Fill(sql,db,True)
With Tables("财务统计_Table1")
.filter=filter
.AutoSizeCols()
.MergeCols.Clear() \'清除原来的合并列
.MergeMode = MergeModeEnum.free \'标准合并模式
.MergeCols.Add("工程名称") \'加入要合并的列
.MergeCols.Add("委托单位")
.MergeSort = "dt" \'设置合并模式下的排序方式
\' .AllowMerge = True \'启用合并模式
\' .GroupAboveData=True \'合计行在数据行之上 \'此属性在这里设置无效
.ListMode=True \'高亮显示当前行
.Cols("委托数量").GrandTotal = True \'指定要合计的列
.Cols("总承载力t").GrandTotal = True
.Cols("小计").GrandTotal = True
.GrandTotal = True \'显示合计模式
End With
ElseIf e.Form.Controls("RadioButton2").checked=True Then \'按检测项目汇总,日报表形式
sql = "Select 产品类别,项目名称,项目代码,桩径,承载力/10 as 承载力t,委托数量,小计,委托编号,area as 区域,gcmc as 工程名称,wtunit as 委托单位,date_wt as 委托日期 FRO M {zjwtsl} inner JOIN {zj} ON {zj}.wtbh = {zjwtsl}.委托编号 where "& dt &" >= \'" & date1 & "\' And "& dt &" <= \'" & date2 & "\'"
Dim b As New CrossTableBuilder("统计",sql,db)
b.HGroups.AddDef("产品类别")
b.HGroups.AddDef("项目名称")
b.VGroups.AddDef(dt, DateGroupEnum.Year, "{0}年")
b.VGroups.AddDef(dt, DateGroupEnum.month, "{0}月")
b.Totals.AddDef("委托数量")
b.HorizontalTotal = True \'横向合计
b.VerticalTotal = True \'纵向合计
b.Decimals = 2
b.Subtotal = True
\'b.Filter=Filter
Tables("财务统计_table1").DataSource = b.Build()
With Tables("财务统计_table1")
.AutoSizeCols()
End With
上面明细可以查询到,按检测项目汇总统计不了。求大神指点