我在数据库中有3个存储过程。它们非常简单和相似。它们都在SQL Server中工作,每秒运行大约1/4。
这些存储过程由Excel文件中的某些VBA代码调用。三个存储过程中的两个运行良好,并在大约1/4秒内返回数据,但其中一个运行大约需要30秒,我不明白为什么。
Sub USPSectorExposure()
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Dim ctr As Integer
Dim sCode As String
Dim dtReport As Date
Dim tStart As Date
tStart = Now()
sCode = "OENN"
dtReport = "2018-02-22"
OpenDbConnection
cmd.ActiveConnection = cn
cmd.Parameters.Append cmd.CreateParameter("Code", adVarWChar, adParamInput, 20, sFund)
cmd.Parameters.Append cmd.CreateParameter("dateHld", adDate, adParamInput, , dtReport)
cmd.CommandText = "uspMyTest"
Set rs = cmd.Execute(, , adCmdStoredProc)
If rs.EOF = False Then
MsgBox Format(Now() - tStart, "hh:mm:ss")
End If
CloseConnection
End Sub