I have a method here which allows you to add Parameters to the Stored Procedure from Excel.
There are quite a few steps, but I’ve broken it down quite alot.
The process is actually really easy once you know how… as with anything.
- Open Excel
- Select the Data Tab (If you’re using Excel 2007 onwards!)
- Select the “From Other Sources” drop down box
- Select “From SQL Server”
- It will open up the following box
- Enter “.SQLExpress” (That’s Dot Backslash SQLExpress and it’s without the quotes) in the “Server name:” box
- Depending on your Server Configuration, either leave the Log on credentials as “Use Windows Authentication”, or select the “Use the following User Name and Password” radio button and enter your SQL Server credentials
- Hit “Next >”
- You should then see the following screen:
- In the “Select the database that contains the data you want:” Dropdown, select the database you wish to use.
- In the list at the bottom, select a table, it doesn’t matter which you choose.
- Press “Next >”
- You should then be presented with the following screen:
- In the “Filename” Textbox, set the name you would like to save the connection as, remembering to leave the “.odc” on the end.
- If you want the Password to be stored with this connection, then check the “Save password in file” Checkbox, say “Yes” to the warning box.
- In the “Description” enter something meaningful for this connection
- In the “Friendly Name:” Textbox, set the name you would like to appear in the Recent Connections dialog. There’s no need for a “.odc” extension here.
- Hit “Finish”
- You should then be shown the following screen:
- Click “Properties…”
- The “Connection Properties” window will be shown:
- Click the “Definition” tab, which will show:
- If required click the “Save password” Checkbox, and press “Yes” to the warning box
- Change the “Command Type” Dropdown to be “SQL”
- Set the “Command text to “exec ” + the name of your Stored Procedure. If you stored procedure requires parameters then simply tack them on the end seperated by commas.
e.g. exec GetUsersByAreaandName Eastern, Smith
If you wish to pass in a Null, then simply type “NULL” as a parameter.e.g. exec GetUsersByAreaandName Eastern, NULL
- Press “OK”, and Press “Yes” to the warning box
- You should be shown the Import Data screen again, Press “OK”
If everything went according to plan, you should have all your data on screen!
Leave A Comment
You must be logged in to post a comment.