Good Afternoon, I am starting a new journey to learn SQL on top of my long usage of VBA
I have built the following
This exports the information I need but... I have a created stored procedure in sql which do the same thing called "extract_cash_balance"
could anyone tell me how to change the above to call the stored procedure rather than create the query in VBA
I tried the code below which resulted in a miserable fail [on the rs.open line]
many thanks in advance
I have built the following
VBA Code:
Sub extract_cash()
Dim conn As ADODB.connection
Dim rs As ADODB.Recordset
Dim sConnString As String, sql As String
Set wkbMacro = ActiveWorkbook
Set wskData = wkbMacro.Worksheets("Cash Transaction Table")
wkbMacro.Worksheets("sheet1").Cells.ClearContents
sConnString = .......
' Create the Connection and Recordset objects.
Set conn = New ADODB.connection
' Open the connection and execute.
conn.Open sConnString
'sql query
sql = "SELECT client_acc, currency, sum(cash_amount) "
sql = sql & "FROM test_cash_trans "
sql = sql & "group by client_acc, currency;"
Set rs = New ADODB.Recordset
rs.Open sql, conn
'export to excel
'wkbMacro.Worksheets("sheet1").Cells(2, 1).CopyFromRecordset rs
End Sub
This exports the information I need but... I have a created stored procedure in sql which do the same thing called "extract_cash_balance"
could anyone tell me how to change the above to call the stored procedure rather than create the query in VBA
I tried the code below which resulted in a miserable fail [on the rs.open line]
VBA Code:
Sub extract_cash()
Dim conn As ADODB.connection
Dim rs As ADODB.Recordset
Dim sConnString As String, sql As String
Set wkbMacro = ActiveWorkbook
Set wskData = wkbMacro.Worksheets("Cash Transaction Table")
wkbMacro.Worksheets("sheet1").Cells.ClearContents
sConnString = ......
' Create the Connection and Recordset objects.
Set conn = New ADODB.connection
' Open the connection and execute.
conn.Open sConnString
rs.Open ("exec extract_cash_balance", conn)
wkbMacro.Worksheets("sheet1").Cells(2, 1).CopyFromRecordset rs
End Sub
many thanks in advance