Excel: Send multiple values in "Command text"

Julian Moreno picture Julian Moreno · Jan 15, 2013 · Viewed 17.8k times · Source

Located in the "Data > Connections > Properties > Definition (tab) > Command text", I have the following:

{Call SP_calculo_algo(?)}

Command Text

Where currently the function receives only one value through the unique parameter that it has, that according with someone told me it is represented by the character of the question mark (?).

What I need is to send two (2) values through the function, since I have the SQL query that returns data that refer to a range between two dates. For example: Start Date (parameter 1) and End Date (parameter 2).

Can you help me?

Answer

Jon Crowell picture Jon Crowell · Jan 16, 2013

Make sure you are using Microsoft Query for your connection.

Data -> From Other Sources -> From Microsoft Query

At the end of the Wizard, make sure you specify "Return data to Microsoft Excel".

After the query executes, the data will be on your worksheet. Click somewhere on the result set, then select the query Data -> Connections -> Properties.

Click on the definition tab. Modify the command text to include the query with question marks as placeholders for your parameters.

MS Query Parameters

Click OK, and you will be prompted for each parameter. Click the box if you want to save the value you enter for future refreshes.

Prompt for MS Query Parameter