简体   繁体   English

从Excel存储过程与参数

[英]stored proc from excel with parameters

如果我在具有参数的sql中创建存储的proc,可以从Excel中运行它吗?

Without using VBA you can use this method. 如果不使用VBA,则可以使用此方法。 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. 我认为您必须使用VBA来做到这一点。

  1. Under the 'Connections' section click 'Connections' 在“连接”部分下,单击“连接”
  2. Click Add 单击添加
  3. Click 'Browse for More...' 点击“浏览更多...”
  4. Click 'New Source...' 点击“新来源...”
  5. Select 'Microsoft SQL Server' 选择“ Microsoft SQL Server”
  6. Click Next 点击下一步
  7. Type in the login credentials and click ok. 输入登录凭据,然后单击“确定”。
  8. Select your database 选择你的数据库
  9. Uncheck 'Connect to a specific table' 取消选中“连接到特定表”
  10. Click Finish. 单击完成。
  11. When asked to select a table just click ok. 当要求选择表格时,单击确定。
  12. This should bring you back to the Workbook Connections screen with your new connection added. 这将使您返回到“工作簿连接”屏幕,并添加了新的连接。
  13. Select it and click 'Properties' 选择它,然后单击“属性”
  14. Go to the 'Definition' tab. 转到“定义”标签。
  15. Set the Command Type to SQL 将命令类型设置为SQL
  16. set the Command text to the SQL you want to run (ie "exec spStoredProc 'value'") 将命令文本设置为要运行的SQL(即“ exec spStoredProc'value'”)
  17. Set a new name for your connection 为您的连接设置新名称
  18. Click ok. 单击确定。
  19. if told that you are severing a connection just agree that, that is okay. 如果告诉您要断开连接,则只需同意即可。
  20. Click 'Close' on your 'Workbook Connections' 在“工作簿连接”上单击“关闭”
  21. Click 'Existing Connections' under the 'Get External Data' section 单击“获取外部数据”部分下的“现有连接”
  22. Select your connection you just made under the 'Connections in this Workbook' section. 在“此工作簿中的连接”部分下选择刚刚建立的连接。
  23. Click Open 点击打开
  24. Set your Import Data options if you want or just click ok 如果需要,请设置“导入数据”选项,或者单击“确定”。
  25. You should now see the result set from the SQL Query in your excel worksheet. 现在,您应该在excel工作表中看到来自SQL查询的结果集。
  26. This data can be refreshed from the data that is in the database by going to the data tab and clicking 'Refresh All' 通过转到“数据”选项卡并单击“全部刷新”,可以从数据库中的数据刷新此数据。

Yes

A standard ADO call from VBA. 来自VBA的标准ADO调用。 Or use the Tools..Data thing. 或使用Tools..Data东西。

I have been working to find a solution to this for a while now and got the best results from following the steps in this article. 我一直在努力寻找一种解决方案,现在,按照本文中的步骤进行操作可获得最佳结果。

http://codebyjoshua.blogspot.com/2012/01/get-data-from-sql-server-stored.html http://codebyjoshua.blogspot.com/2012/01/get-data-from-sql-server-stored.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM