Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2398
  • Last Modified:

T-SQL way to export from SQL table to .csv/.xlsx ?

Hi All

Question:  Is there a T-SQL way to export data from a SQL table to a .csv or .xlsx?
I'm familiar with SSIS, but would like to avoid the work and overhead if that is possible.

I have an Access 2010 FE / SQL 2008 R2 backend, and the backend contains a table that is too wide to be linked to Access, so afaik I can't take advantage of Access' export specs.  

Ultimately I'll have an Access form that allows a user to choose between different exports, then Access VBA will execute a Stored Procedure that populates the table with data.  I just need to figure out how to build the piece that exports it.

Thanks in advance.
Jim Horn
Jim Horn
4 Solutions
Scott PletcherSenior DBACommented:
You can use "bcp" to export to a csv format.

I don't know of any way to directly export to Excel from SQL w/o using SSIS/package.
SThayaTechnical MAnagerCommented:
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
<Going the SSIS wizard route for the moment.  I'll change paths to either bcp or the SSIS designer if this doesn't work>

I went into the db, right click Tasks > Export Data ... and followed the wizard.

Three questions:
(1)  Once saved, is there a T-SQL command that can be executed to execute the package?
(2)  Where in SSMS can I view the saved package?
(3)  I'm receiving the below error message when I attempt to save the package, which I'm guessing is a privs issue I need to work out with my DBA's:
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:

I pieced together the below T-SQL from your links, and received the below error message:
BCP errmsg
I'll work out the privs with the DBA's as well.
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
Splitting points.  I'm sure that bcp would have worked, as it executed on my personal box, but due to restrictions at my company (shocking I know) I'm not able to execute bcp.  Or save SSIS packages to the server.  

So, I'm creating SSIS using the wizard, then modifying to fit my template.

Anthony PerkinsCommented:
Or save SSIS packages to the server.  
You don't have to (in fact you probably should not) save the SSIS packages on the same server as SQL Server.
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
Anthony - Yep.  I don't have any experience with SSIS on the server, as every place I've worked we've ran them off of the file system.  Not sure what the DBA resistance is to SSIS on the server.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now