Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 使用多个工作表和自定义标题将SQL查询导出到excel_Sql Server_Reporting Services_Export To Excel - Fatal编程技术网

Sql server 使用多个工作表和自定义标题将SQL查询导出到excel

Sql server 使用多个工作表和自定义标题将SQL查询导出到excel,sql-server,reporting-services,export-to-excel,Sql Server,Reporting Services,Export To Excel,我需要做的是,客户希望excel文档中有一个报表,其中包含多个带有自定义标题的工作表。我尝试过SSRS 2008 Report Builder 2.0,但命名工作表在SSRS 2008 Report Builder 2.0中不可用。我在SQLServerManagementStudio中尝试过bcp,但无法将其导出到多个工作表中。我已将查询放入临时表中,是否有方法将这些查询导出到相同的excel文档中,但不同的工作表中,每个工作表的标题不同 像这样 请注意,每个工作表都有不同的名称和标题 这是

我需要做的是,客户希望excel文档中有一个报表,其中包含多个带有自定义标题的工作表。我尝试过SSRS 2008 Report Builder 2.0,但命名工作表在SSRS 2008 Report Builder 2.0中不可用。我在SQLServerManagementStudio中尝试过bcp,但无法将其导出到多个工作表中。我已将查询放入临时表中,是否有方法将这些查询导出到相同的excel文档中,但不同的工作表中,每个工作表的标题不同

像这样

请注意,每个工作表都有不同的名称和标题


这是否可以通过SQL实现,或者SSRS 2008 Report Builder 2.0是否有解决方案?

您可以使用SQL Server Integration Services 2008R2(SSIS)来实现这一点。SSIS有一个Excel数据流目标,它接受工作表名称作为参数。您可以通过这种方式构建SSIS包来填充电子表格的各种工作表。

我知道,我知道。。。你也面临着错误:

Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource’ of component ‘Ad Hoc Distributed Queries’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘Ad Hoc Distributed Queries’ by using sp_configure. For more information about enabling ‘Ad Hoc Distributed Queries’, search for ‘Ad Hoc Distributed Queries’ in SQL Server Books Online.
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'Ad Hoc Distributed Queries', 1
RECONFIGURE
您可以通过T-SQL在SSMS中执行此操作,如下所示:

首先,您需要允许SSM绕过错误:

Msg 15281, Level 16, State 1, Line 1
SQL Server blocked access to STATEMENT ‘OpenRowset/OpenDatasource’ of component ‘Ad Hoc Distributed Queries’ because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of ‘Ad Hoc Distributed Queries’ by using sp_configure. For more information about enabling ‘Ad Hoc Distributed Queries’, search for ‘Ad Hoc Distributed Queries’ in SQL Server Books Online.
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'Ad Hoc Distributed Queries', 1
RECONFIGURE
然后,您可以通过以下方式将结果保存在精确的Excel选项卡中:

INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;
Database=C:\Users\Zivko\Desktop\SQL Data.xlsx;','SELECT * FROM [Sheet1$]') 
SELECT * FROM dbo.DimScenario

文件.XLSX必须已经存在,并且选项卡的确切名称为
[Sheet1$]

我从未使用过SSIS。您能带我浏览一下它以开始吗?