将数据从SQL Server导出到Microsoft Excel数据表

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将数据从SQL Server导出到Microsoft Excel数据表相关的知识,希望对你有一定的参考价值。

How to Export Data From SQL Server to Microsoft Excel Datasheet
  1. --Enable Ad Hoc Distributed Queries. Run following code in SQL Server Management Studio – Query Editor.
  2. EXEC sp_configure 'show advanced options', 1;
  3. GO
  4. RECONFIGURE;
  5. GO
  6. EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
  7. GO
  8. RECONFIGURE;
  9. GO
  10. --Create Excel Spreadsheet in root directory c:contact.xls (Make sure you name it contact.xls). Open spreadsheet, on the first tab of Sheet1, create two columns with FirstName, LastName. Alternatively you can download sample Spreadsheet from here.
  11.  
  12. --Run following code in SQL Server Management Studio – Query Editor.
  13. USE [AdventureWorks];
  14. GO
  15. INSERT INTO OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=c:contact.xls;',
  16. 'SELECT * FROM [Sheet1$]')
  17. SELECT TOP 5 FirstName, LastName
  18. FROM Person.Contact
  19. GO
  20. --Open contact.xls spreadsheet you will see first five records of the Person.Contact inserted into the first two columns.
  21. --Make sure your spreadsheet is closed during this operation. If it is open it may thrown an error. You can change your spreadsheet name as well name of the Sheet1 to your desired name.

以上是关于将数据从SQL Server导出到Microsoft Excel数据表的主要内容,如果未能解决你的问题,请参考以下文章

如何将 Excel 数据从不同的工作表导出到 SQL-SERVER 数据库?

将数据从SQL Server导出到Microsoft Excel数据表

SQL Server2012使用导入和导出向导时,用sql语句作为数据源,出现数据源类型会变成202或者203

将数据从 MS Sql Server 存储过程导出到 excel 文件

将数据从 SQL Server Express 导出到 CSV(需要引用和转义)

如何将数据库从mysql工作台导出到sql server