If I create a stored proc in sql that has a parameter, can I run that from Excel?
+2
A:
Sure, you can use VBA.
Or you can do it like this: http://blogs.msdn.com/b/excel/archive/2010/06/08/running-a-sql-stored-procedure-from-excel-no-vba.aspx
Here's another nice article on it.
David Stratton
2010-09-02 18:13:12
+1
A:
Without using VBA you can use this method. This assumes your stored procedure returns a result set. It also does not make the parameter pulled from a workbook. I think you'd have to use VBA to do that.
- Under the 'Connections' section click 'Connections'
- Click Add
- Click 'Browse for More...'
- Click 'New Source...'
- Select 'Microsoft SQL Server'
- Click Next
- Type in the login credentials and click ok.
- Select your database
- Uncheck 'Connect to a specific table'
- Click Finish.
- When asked to select a table just click ok.
- This should bring you back to the Workbook Connections screen with your new connection added.
- Select it and click 'Properties'
- Go to the 'Definition' tab.
- Set the Command Type to SQL
- set the Command text to the SQL you want to run (i.e. "exec spStoredProc 'value'")
- Set a new name for your connection
- Click ok.
- if told that you are severing a connection just agree that, that is okay.
- Click 'Close' on your 'Workbook Connections'
- Click 'Existing Connections' under the 'Get External Data' section
- Select your connection you just made under the 'Connections in this Workbook' section.
- Click Open
- Set your Import Data options if you want or just click ok
- You should now see the result set from the SQL Query in your excel worksheet.
- This data can be refreshed from the data that is in the database by going to the data tab and clicking 'Refresh All'
GluedHands
2010-09-02 19:07:44