MojoJojo2023
New Member
- Joined
- Aug 7, 2023
- Messages
- 9
- Office Version
- 365
- 2021
- 2019
- Platform
- Windows
Hello all,
I use a simple report daily that is copy and pasted into an excel worksheet where it is analyzed. It can be quite a pain to get into the system for this report everyday, so I would like to take the SQL code and return the results directly into my worksheet using VBA. I have used ADODB connections to query the server before, but have not attempted anything like this before. The code I am trying to pass is being shown to me similar to the below:
Create #DealTable (
[DealName] varchars(45)
,[DealNumber] varchars(45)
,[Location] varchars (45),
)
Insert into #DealTable execute dbo.DealTrack @IDLog
Select
[#DealTable].[DealName] [DealName]
,[#DealTable].[DealNumber] [DealNumber]
,[#DealTable].[Location] [Location]
From [#DealTable] (NoLock)
'N, @IDLog = 1
I understand that this code is 1) Creating a table, 2) Filling the table based on the output of a stored procedure, 3) querying the temporary table, and 4) passing the selected parameter to the stored procedure. Should I pass it all through under one ADODB Recordset? Should I break into three distinct parts (ADODB.Recordset, ADODB.Command, then Recordset again)? OR is there a better alternative?
I love VBA and am really trying to refine my approach, so any help would be greatly appreciated!
I use a simple report daily that is copy and pasted into an excel worksheet where it is analyzed. It can be quite a pain to get into the system for this report everyday, so I would like to take the SQL code and return the results directly into my worksheet using VBA. I have used ADODB connections to query the server before, but have not attempted anything like this before. The code I am trying to pass is being shown to me similar to the below:
Create #DealTable (
[DealName] varchars(45)
,[DealNumber] varchars(45)
,[Location] varchars (45),
)
Insert into #DealTable execute dbo.DealTrack @IDLog
Select
[#DealTable].[DealName] [DealName]
,[#DealTable].[DealNumber] [DealNumber]
,[#DealTable].[Location] [Location]
From [#DealTable] (NoLock)
'N, @IDLog = 1
I understand that this code is 1) Creating a table, 2) Filling the table based on the output of a stored procedure, 3) querying the temporary table, and 4) passing the selected parameter to the stored procedure. Should I pass it all through under one ADODB Recordset? Should I break into three distinct parts (ADODB.Recordset, ADODB.Command, then Recordset again)? OR is there a better alternative?
I love VBA and am really trying to refine my approach, so any help would be greatly appreciated!