我有sql查询,它根据三个标准返回一些字段。
但我收到错误"两个参数2"错误。
Sub Test()
Dim rs As DAO.Recordset
Dim sqlMax As String
Dim result As Integer
Dim startd, endd As String
startd = Me.txtsdate.Value
endd = Me.txtedate.Value
sqlMax = "SELECT Sum(Salesdata.FOOD) AS SumOfFOOD, Sum(Salesdata.LIQUORS) AS SumOfLIQUORS, Sum(Salesdata.SMARTPORTION) AS SumOfSMARTPORTION, Sum(Salesdata.[SP TAKEAWAY]) AS [SumOfSP TAKEAWAY]," _
& "Sum(Salesdata.TAKEAWAY) AS SumOfTAKEAWAY, Sum(Salesdata.TAX_KKCESS02) AS SumOfTAX_KKCESS02, Sum(Salesdata.TAX_SBC020) AS SumOfTAX_SBC020, Sum(Salesdata.TAX_SERVICECHARGE) AS SumOfTAX_SERVICECHARGE," _
& "Sum(Salesdata.TAX_VAT145) AS SumOfTAX_VAT145, Sum(Salesdata.AMEX) AS SumOfAMEX, Sum(Salesdata.CASH) AS SumOfCASH, Sum(Salesdata.MASTERCARD) AS SumOfMASTERCARD, Sum(Salesdata.VISA) AS SumOfVISA, Sum(Salesdata.OTHERS) AS SumOfOTHERS," _
& "Sum(Salesdata.Vcloud) AS SumOfVcloud, Sum(Salesdata.MANAGERAC) AS SumOfMANAGERAC FROM Salesdata" _
& "WHERE (((Salesdata.Loc) = 'Alipore'))" _
& "HAVING (((Salesdata.DATE)>=" & startd & " And (Salesdata.DATE)<=" & endd & "));"
设置rs = CurrentDb.OpenRecordset(sqlMax,dbOpenDynaset)
Set rs = CurrentDb.OpenRecordset(sqlMax)
result = rs.Fields(0)
MsgBox result
Set rs = Nothing
rs.Close
End Sub
答案 0 :(得分:0)
应该是
&安培; &#34; WHERE(((Salesdata.Loc)=&#39; Alipore&#39;))&#34; _
而不是
&安培; &#34; WHERE(((Salesdata.Loc)=&#39; Alipore&#39;))&#34; _