• <bdo id='18iIc'></bdo><ul id='18iIc'></ul>
        <tfoot id='18iIc'></tfoot>

        <small id='18iIc'></small><noframes id='18iIc'>

        <legend id='18iIc'><style id='18iIc'><dir id='18iIc'><q id='18iIc'></q></dir></style></legend>
        <i id='18iIc'><tr id='18iIc'><dt id='18iIc'><q id='18iIc'><span id='18iIc'><b id='18iIc'><form id='18iIc'><ins id='18iIc'></ins><ul id='18iIc'></ul><sub id='18iIc'></sub></form><legend id='18iIc'></legend><bdo id='18iIc'><pre id='18iIc'><center id='18iIc'></center></pre></bdo></b><th id='18iIc'></th></span></q></dt></tr></i><div id='18iIc'><tfoot id='18iIc'></tfoot><dl id='18iIc'><fieldset id='18iIc'></fieldset></dl></div>

        在SSMS中将存储过程结果集导出到Excel

        Export stored procedure result set to Excel in SSMS(在SSMS中将存储过程结果集导出到Excel)
        <i id='iu8Wz'><tr id='iu8Wz'><dt id='iu8Wz'><q id='iu8Wz'><span id='iu8Wz'><b id='iu8Wz'><form id='iu8Wz'><ins id='iu8Wz'></ins><ul id='iu8Wz'></ul><sub id='iu8Wz'></sub></form><legend id='iu8Wz'></legend><bdo id='iu8Wz'><pre id='iu8Wz'><center id='iu8Wz'></center></pre></bdo></b><th id='iu8Wz'></th></span></q></dt></tr></i><div id='iu8Wz'><tfoot id='iu8Wz'></tfoot><dl id='iu8Wz'><fieldset id='iu8Wz'></fieldset></dl></div>

          • <tfoot id='iu8Wz'></tfoot>
            <legend id='iu8Wz'><style id='iu8Wz'><dir id='iu8Wz'><q id='iu8Wz'></q></dir></style></legend>

              <small id='iu8Wz'></small><noframes id='iu8Wz'>

                  <tbody id='iu8Wz'></tbody>
                  <bdo id='iu8Wz'></bdo><ul id='iu8Wz'></ul>
                • 本文介绍了在SSMS中将存储过程结果集导出到Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 SSMS 并尝试将存储过程的结果导出到新的 excel 文件.SP 接受一个 int 参数,但我找不到在查询中调用它的方法.

                  i'm using SSMS and attempting to export the results of a stored procedure to a new excel file. The SP accepts an int parameter but I cannot find a way to call it in the query.

                  最新努力-

                  EXEC sp_makewebtask 
                      @outputfile = 'C:UsersmeDocuments	esting.xls', 
                      @query = **ExportAsExcel** N'@id' = 123
                      @colheaders =1, 
                      @FixedFont=0,@lastupdated=0,@resultstitle='Testing details'
                  

                  运行存储过程会产生两个数据表,我需要在单独的工作表上.你们中的任何人都可以提出更好的方法来解决这个问题吗?它甚至不需要自动化,我只需要获取正确的数据.sp 名称在上方以粗体显示.

                  Running the stored procedure results in two tables of data, which I need on separate sheets. Can any of you advise a better way to go about this? It doesn't even need to be automated, I just need to get the correct data. The sp name is bolded above.

                  感谢您的时间,

                  H

                  推荐答案

                  我建议您将存储过程拆分为两个过程,每个过程分别返回一个单独的表并将它们调用到不同的工作表.

                  I suggest you split your stored procedure into two procedures that each respectively return a separate table and have those called to different worksheets.

                  使用SQL将数据返回到Excel有多种方式

                  There are a variety of ways to return data to Excel using SQL

                  这是我的最爱,来自 Joshua 的代码(您不必使用参数):

                  Here is a favourite of mine from code by Joshua (you don't have to use the parameters):

                  1. 选择 Excel 功能区上的数据"选项卡,然后在获取外部数据"组中选择来自其他来源"下拉列表.然后选择来自 Microsoft Query"

                  1. Select the Data tab on Excel's Ribbon, then within the Get Exernal Data group choose the "From other Sources" drop-down. Then Choose "From Microsoft Query"

                  在选择数据源"弹出框中,选择您的 SQL Server,然后点击确定.

                  Within "Choose Data Source" pop-up box, select your SQL Server, then hit OK.

                  如有必要,关闭添加表"弹出窗口.

                  Close the "Add Tables" popup if necessary.

                  单击SQL"按钮,或选择查看">SQL"以打开 SQL 弹出式编辑器.

                  Click on the "SQL" button, or choose View > SQL to open the SQL pop-up editor.

                  输入以下语法:{CALL myDatabaseName.dbo.myStoredProc (?, ?, ?)}

                  Enter the following syntax: {CALL myDatabaseName.dbo.myStoredProc (?, ?, ?)}

                  例如:{CALL northwind.dbo.spGetMaxCost (?, ?, ?)}

                  For example: {CALL northwind.dbo.spGetMaxCost (?, ?, ?)}

                  请务必在 call 语句周围包含花括号.每个问号 (?) 表示一个参数.如果您的存储过程需要更多或更少的参数,请根据需要添加或减去问号.

                  Be sure to include the squiggly braces around the call statement. Each Question Mark (?) indicates a parameter. If your stored procedure calls for more or less parameters, add or subtract question marks as needed.

                  点击确定按钮.应该会弹出一个问题框,上面写着SQL 查询无法以图形方式表示,还要继续吗?",只需点击确定"按钮即可.

                  Hit the OK button. A question box should pop-up saying "SQL Query can't be represented graphically, continue anyway?", just hit the OK button.

                  现在将要求您提供上面包含的每个问号的示例参数.为您要查询的数据输入有效的参数值.

                  You will now be asked for sample parameters for each question mark you included above. Enter valid parameter values for the data you are querying.

                  输入最后一个参数后,您应该会在 Microsoft Query 中返回一些结果.如果它们看起来不错,请关闭 Microsoft Query.

                  Once you have entered the last parameter, you should get some results back in Microsoft Query. If they look good, close Microsoft Query.

                  您现在应该看到导入数据"弹出窗口.单击属性"按钮,这将显示连接属性"弹出窗口.

                  You should now be looking at an "Import Data" pop-up. Click the Properties button, which will bring up the "Connection Properties" pop-up.

                  选择定义"选项卡,然后选择参数"按钮.您现在应该会看到一个参数"弹出窗口,您可以在其中将参数连接到特定单元格.

                  Select the Definition tab, then select the Parameters button. You should now see a "Parameters" pop-up, where you can connect the parameter to a specific cell.

                  选择从以下单元格获取值,然后通过单击带有箭头的小框连接到 Excel 中将保存参数的适当单元格.

                  Select Get the value from the following cell, and then connect to an appropriate cell in Excel that will hold your parameter, by clicking the little box with the arrow.

                  如果您希望每次更改包含参数的单元格时都刷新数据,请选中单元格值更改时自动刷新"框

                  If you want the data to refresh every time you change the cell containing the parameter, check the box stating "Refresh automatically when cell value changes"

                  其他参数如上继续.完成后,单击确定"以返回连接属性"弹出窗口.单击确定"返回导入数据"弹出窗口,然后再次单击确定".

                  Continue as above for the other parameters. When finished, click OK, to return to the Connection Properties pop-up. Click OK to return to the Import Data pop-up, and click OK again.

                  您现在应该可以直接从存储过程获得一些数据.

                  You should now have some data straight from your stored procedure.

                  您最终会得到类似于以下内容的连接信息:

                  You will end up with connection information similar to:

                  连接信息

                  而且,如果您使用工作表中的参数,那么在我的示例中,

                  And, if you use parameters from sheet then, for my example,

                  这篇关于在SSMS中将存储过程结果集导出到Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32)(超出最大存储过程、函数、触发器或视图嵌套级别(限制 32))
                  How to debug stored procedure in VS 2015?(如何在 VS 2015 中调试存储过程?)
                  How to find a text inside SQL Server procedures / triggers?(如何在 SQL Server 程序/触发器中查找文本?)
                  SQL Server stored procedure return code oddity(SQL Server 存储过程返回码奇怪)
                  Conditional SQL ORDER BY ASC/DESC for alpha columns(alpha 列的条件 SQL ORDER BY ASC/DESC)
                  How do I call an Oracle stored procedure from an Excel VBA script?(如何从 Excel VBA 脚本调用 Oracle 存储过程?)
                  <tfoot id='XHLO5'></tfoot>

                    <small id='XHLO5'></small><noframes id='XHLO5'>

                          • <bdo id='XHLO5'></bdo><ul id='XHLO5'></ul>
                          • <legend id='XHLO5'><style id='XHLO5'><dir id='XHLO5'><q id='XHLO5'></q></dir></style></legend>

                            <i id='XHLO5'><tr id='XHLO5'><dt id='XHLO5'><q id='XHLO5'><span id='XHLO5'><b id='XHLO5'><form id='XHLO5'><ins id='XHLO5'></ins><ul id='XHLO5'></ul><sub id='XHLO5'></sub></form><legend id='XHLO5'></legend><bdo id='XHLO5'><pre id='XHLO5'><center id='XHLO5'></center></pre></bdo></b><th id='XHLO5'></th></span></q></dt></tr></i><div id='XHLO5'><tfoot id='XHLO5'></tfoot><dl id='XHLO5'><fieldset id='XHLO5'></fieldset></dl></div>
                              <tbody id='XHLO5'></tbody>