' 1. 今日以前
columnNames.Add("今日以前")
' 修正字符串拼接,使用 & 替代 $"" 插值
dateConditions.Add("DDEDT < '" & currentDate & "'")
' 2. 生成10个3天区间(从今日开始)
Dim startDate As Date = currentDate
For i As Integer = 0 To 9
Dim endDate As Date = startDate.AddDays(3)
columnNames.Add(endDate.ToString("M月d日"))
' 修正字符串拼接
dateConditions.Add("DDEDT BETWEEN '" & startDate & "' AND '" & endDate.AddDays( - 1) & "'")
startDate = endDate
Next
' 3. 最后一个区间(最后一个3天区间的次日及以后)
Dim lastDate As Date = startDate
columnNames.Add(lastDate.ToString("M月d日") & "以后")
' 修正字符串拼接
dateConditions.Add("DDEDT >= '" & lastDate & "'")
'-------------------------------------------
' 步骤2:构建SQL统计
'-------------------------------------------
Dim bd As New SQLGroupTableBuilder("动态统计", "v_corder_no_debt_amt")
bd.C ' 指定数据库连接名
bd.Groups.AddDef("ccode")
For i As Integer = 0 To columnNames.Count - 1
Dim sqlExp As String = "CASE WHEN " & dateConditions(i) & " THEN (dqty - dsaleqty) ELSE 0 END"
bd.Totals.AddExp(columnNames(i), sqlExp)
Next
……