下面把sel ect 中的空格去掉
Dim cmd As new SQLCommand
cmd.CommandText = "sel ect year(日期) as 年, month(日期) as 月, sum(销售额) AS 销售额, sum(销售成本) AS 销售成本, sum(销售支出) AS 销售支出, sum(返点支出) AS 返点支出 from (Sel ect 订单日期 as 日期,销售额, [销售成本], 0 as 销售支出, 0 as 返点支出 from {表A} union all sel ect 支出日期 as 日期, 0 as 销售额, 0 as 销售成本,销售支出 ,返点支出 from {表C}) as c group by year(日期), month(日期)"
Dim dt As DataTable = cmd.ExecuteReader
Dim Cols1() As String = {"年", "月", "销售额", "销售成本", "销售支出", "返点支出"}
Dim Cols2() As String = {"年", "月", "销额统计", "销售成本月计", "营业成本统计", "返点金额"}
For Each dr1 As DataRow In dt.Sel ect("年 is not null")
Dim dr2 As DataRow = DataTables("表B").AddNew()
For i As Integer = 0 To Cols1.Length -1
dr2(Cols2(i)) = dr1(Cols1(i))
Next
Next