Need help with Sql to Excel code

lillypop

New Member
Joined
Jul 20, 2018
Messages
14
Hello

I need to import a data table from SQL to Excel. I have the 2 queries in stored procedures (one that provides one part of the data table, and another provides the other half of the data in the table). What I want to do is for users to key in the start and end dates in Excel and the program should run itself and present the result data in Excel sheet. Is anything missing here?


Sub Outcome()


Dim avarParame As Variant
Dim avarValues As Variant
Dim avarResult As Variant
Dim avarResult2 As Variant
Dim wks As Worksheet
Dim strPath As String
Dim strFileName As String


'excel variables


Mnemonic = Range("strMnemonic")
datFrom = CDate(Range("DateFrom").Value)
datTo = CDate(Range("DateTo").Value)


ReDim avarParam(0 To 1)
ReDim avarValues(0 To 1)


avarParam(0) = "@datStart"
avarParam(1) = "@datCurrent"


avarValues(0) = datStart
avarValues(1) = datCurrent


'launch stored procedure1


avarResult = avarStoredProcedure("pTransaction1", avarParam, avarValues, "dbsMainBase")


Range(Range("Output"), Range("Output").Offset(UBound(avarResult, 1), UBound(avarResult, 2))) = avarResult




'launch stored procedure2
avarResult2 = avarStoredProcedure("pTransaction2", avarParam, avarValues, "dbsMainBase")


Range(Range("Output"), Range("Output").Offset(UBound(avarResult, 1), UBound(avarResult2, 2))) = avarResult2




End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top