SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Export all tables of database to Excel
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

7 Posts

Posted - 02/16/2013 :  19:42:46  Show Profile  Reply with Quote
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

Starting Member

7 Posts

Posted - 02/16/2013 :  20:04:44  Show Profile  Reply with Quote
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)

Go to Top of Page

Very Important crosS Applying yaK Herder

52325 Posts

Posted - 02/17/2013 :  02:28:16  Show Profile  Reply with Quote
The Excel files can be created using OPENROWSET or bcp





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

SQL Server MVP

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000