我怎樣才能改變我的VBA代碼,以便它會設法在SQL查詢運行臨時表 這是我的VBA代碼(存儲過程包含臨時表)不能在VBA使用SQL臨時表(不能刪除表)
Sub a()
Dim connection As ADODB.connection
Dim recordset As ADODB.recordset
Dim command As ADODB.command
Dim strProcName As String 'Stored Procedure name
Dim strConn As String ' connection string.
Dim selectedVal As String
Set connection = New ADODB.connection
Set recordset = New ADODB.recordset
Set command = New ADODB.command
strConn = "Provider=SQLOLEDB.1;Persist Security Info=true;Data source =1.1.2.7\B;User ID = sa; password=a;Initial catalog=A"
connection.ConnectionString = strConn
connection.Open
command.ActiveConnection = connection
command.CommandText = "pLOAN_LIST"
command.CommandType = adCmdStoredProc
command.Parameters.Refresh
'command.Parameters(1).Value = "3"
Set recordset = command.Execute()
ThisWorkbook.Sheets("Sheet1").Cells(1, 1).CopyFromRecordset recordset
recordset.Close
Set recordset = Nothing
connection.Close
Set connection = Nothing
End Sub
你在問什麼?目前尚不清楚 – MikkaRin