我写了一些VBA代码来执行SQL语句:
Dim Cn As New ADODB.Connection
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Dim i As Long
Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & ThisWorkbook.FullName & ";" & _
"Extended Properties=""Excel 8.0;"""
Cn.Open
cmd.ActiveConnection = Cn
cmd.CommandText = "DECLARE @TS_HD DOUBLE;" & _
"SET @TS_HD = ?TS_HD;" & _
"SELECT So_HD, Ngay_HD, Ten_Khach_Hang, Ma_So_Thue, Sum(Doanh_So_KT) as DoanhSo, Sum(Thue_VAT) as VAT from [BR$] " & _
"Where Ngay_HD <> null And TS_HD = @TS_HD Group by So_HD, Ma_So_Thue,Ngay_HD, Ten_Khach_Hang Order by Ngay_HD"
Set TS_HD = cmd.CreateParameter("?TS_HD", adDouble, adParamInput)
cmd.Parameters.Append TS_HD
TS_HD.Value = 0.1 'in excel this value is 10%'
Dim rst As ADODB.Recordset
Set rst = cmd.Execute()
BRToTalKhongChiuThue() = rst.GetRows
rst.Close
Cn.Close
当我运行此代码时,我收到运行时VBA错误,指出“预期无效的SQL语句;'删除','插入',”
我的SQL语句出了什么问题?