试试以下这个代码
Dim 日期1 As String = "format(DateAdd('d', -iif(DatePart('w', 日期)=1,8,DatePart('w', 日期))+2, 日期),'yymmdd')"
Dim 日期2 As String = "format(DateAdd('d', -iif(DatePart('w', 日期)=1,8,DatePart('w', 日期))+8, 日期),'yymmdd')"
Dim bm As String = "窗口1_Table2"
Dim b As New SQLCrossTableBuilder(bm,"销售")
b.HGroups.AddExp("营业额_日期", "trim(str(" & 日期1 & "))+'-'+trim(str(" & 日期2 & "))")
b.VGroups.AddExp("星期","DatePart('w', 日期)")
b.Totals.AddDef("营业额")
b.HorizontalTotal = True
Tables(bm).DataSource = b.Build(True)
Tables(bm).Cols("营业额_1").Move(Tables(bm).Cols.Count-2)
For Each c As Col In Tables(bm).Cols
If len(c.Caption) = 5
c.Caption = left(c.Caption,4) & "星期" & CLNum(CInt(right(c.Caption,1))-1)
End If
If c.Name = "营业额_1"
c.Caption = "营业额_星期日"
ElseIf c.Name = "合计"
c.Caption = "营业额_合计"
End If
Next
DataTables(bm).BuildHeader
Tables(bm).AutoSizeCols
'注明:窗口控件table2不要绑定任何表
[此贴子已经被作者于2018/5/13 13:29:43编辑过]