I am creating an .xlsm file which contains a report with three input parameters. After inputting the parameters, the end user then runs a macro which sends the parameters to a stored procedure, runs the stored procedure, and displays the data back in Excel.
I have the proc running nicely, but now, for two of the three parameters (@AccountNumber and @ActiveAgreement), the end user would like the option to input more than one value for each. Here is my current macro code:
Sub RefreshQuery()
With ActiveWorkbook.Connections("ImpactDetailSheet").OLEDBConnection
.CommandText = "DECLARE @PriceList NVARCHAR(10), @AccountNumber NVARCHAR(10), @ActiveAgreement NVARCHAR(10) SET @PriceList = '" & Range("J1").Value & "' SET @AccountNumber = '" & Range("J2").Value & "' SET @ActiveAgreement = '" & Range("J3").Value & "' EXEC [dbo].[Impact] @PriceList, @AccountNumber, @ActiveAgreement"
End With
ActiveWorkbook.Connections("ImpactDetailSheet").Refresh
ActiveWorkbook.Connections("ImpactActiveAgreementSheet").Refresh
ActiveWorkbook.Connections("ImpactKickoutSheet").Refresh
End Sub
My question is how do I alter the code to include more than one value for a given parameter? From what I can tell, I will need to update my stored procedure to use parentheses around the parameters (e.g. (@AccountNumber)) if I'm using a list.
Also, is it possible to have 1 cell that contains multiple parameters? For example, separated by a comma or something similar, vs. using multiple cells for additional parameters.
Many thanks in advance.