简体   繁体   English

Excel 中的存储过程结果

[英]Stored Procedure results in Excel

I have a requirement to provide the results of my analysis in different sheets under one excel file.我需要在一个 excel 文件下的不同表格中提供我的分析结果。 Currently i'm manually copying and pasting the results into excel (10 sheets).目前我正在手动将结果复制并粘贴到 excel(10 张)中。 How I can use the stored procedure to automate this?我如何使用存储过程来自动执行此操作?

I have tried something like below.我已经尝试过类似下面的东西。

insert into OPENROWSET(
   'Microsoft.Jet.OLEDB.4.0', 
   'Excel 8.0;Database=D:\Results\test.xls;;HDR=YES', 
   'SELECT * FROM [Sheet1$]')
select * from MY_TABLE WHERE ATTR='YES'

insert into OPENROWSET(
   'Microsoft.Jet.OLEDB.4.0', 
   'Excel 8.0;Database=D:\Results\test.xls;;HDR=YES', 
   'SELECT * FROM [Sheet2$]')
select * from MY_TABLE WHERE ATTR='No'

It is giving me error它给了我错误

SQL Server blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'Ad Hoc Distributed Queries' SQL 服务器阻止访问组件“即席分布式查询”的声明“OpenRowset/OpenDatasource”

I will try to get the access from admin.Hopefully after that it will work?我会尝试从管理员那里获得访问权限。希望之后它会起作用吗? But Is there any other way of doing this?但是有没有其他方法可以做到这一点? Also I want to know how to do this inside a procedure for providing the results in different sheets.此外,我想知道如何在一个程序中执行此操作,以便在不同的工作表中提供结果。

Try this code:试试这个代码:

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'AllowInProcess', 1
GO 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'DynamicParameters', 1
GO 

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

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