代码:
Sub test()
Dim CNN As New ADODB.Connection
Dim Cmd As New ADODB.Command
Dim Par As New ADODB.Parameter
Dim RST As New ADODB.Recordset
CNN.Open "Driver=Microsoft Access Driver (*.mdb);DBQ=c:\db1.mdb;"
With Cmd
.ActiveConnection = CNN
.CommandText = "myQuery"
.CommandType = adCmdStoredProc
Set Par = .CreateParameter("LngP", adInteger, adParamInput, , 200604)
.Parameters.Append Par
Set RST = .Execute
End With
MsgBox RST.RecordCount
End Sub
DB1之表TB:
CODE DESCRIPTION AMOUNT PERIOD
123 现金 ¥2,566 200601
123 现金 ¥36,555 200602
123 现金 ¥35,555 200603
222 银行存款 ¥55,568 200601
222 银行存款 ¥533,489 200602
222 银行存款 ¥35,789 200603
DB1之myQuery:
PARAMETERS lngp Long;
SELECT description, sum(amount)
FROM tb
WHERE period<=lngp
GROUP BY description;