Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Export all tables of database to Excel

Author  Topic 

Angeline87
Starting Member

7 Posts

Posted - 2013-02-16 : 19:42:46
Hi to everybody

How can I export all tables of a database to one excel file (each table should be one spreadsheet in the excel file) by using SQL Code?

Important remarks:
- The export should be generated via (T-)SQL Code not else how.
- I am using SQL Server 2008 R2
- I am using MS Office 2007

Any ideas?

Thanks a lot for your support in advance
Angeline

Angeline87
Starting Member

7 Posts

Posted - 2013-02-16 : 20:04:44
Additional requirements
- The Excel File should be created by SQL Code (it does not exist in advance)
- The tablenames are dynamic; I don't know the names in advance. Therefore the skript should dynamically read table names (using something like a for-loop)

Thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-17 : 02:28:16
The Excel files can be created using OPENROWSET or bcp

OPENROWSET

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926


bcp



http://www.dotnetspider.com/resources/28884-Export-Sql-Server-table-CSV-Excel-Txt-Files.aspx

The looping can be done by means of WHILE loop by retrieving table names from INFORMATION_SCHEMA.TABLES catalog view

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -