How to export SQL Server 2005 query to CSV

后端 未结 13 2641

I want to export some SQL Server 2005 data to CSV format (comma-separated with quotes). I can think of a lot of complicated ways to do it, but I want to do it the right<

相关标签:
13条回答
  • 2020-12-04 15:56

    I think the simplest way to do this is from Excel.

    1. Open a new Excel file.
    2. Click on the Data tab
    3. Select Other Data Sources
    4. Select SQL Server
    5. Enter your server name, database, table name, etc.

    If you have a newer version of Excel you could bring the data in from PowerPivot and then insert this data into a table.

    0 讨论(0)
  • 2020-12-04 15:57

    You can use following Node.js module to do it with a breeze:

    https://www.npmjs.com/package/mssql-to-csv

    0 讨论(0)
  • 2020-12-04 15:58

    SSIS is a very good way to do this. This can be then scheduled using SQL Server Agent jobs.

    0 讨论(0)
  • 2020-12-04 16:01

    I had to do one more thing than what Sijin said to get it to add quotes properly in SQL Server Management Studio 2005. Go to

    Tools->Options->Query Results->Sql Server->Results To Grid

    Put a check next to this option:

    Quote strings containing list separators when saving .csv results

    Note: the above method will not work for SSMS 2005 Express! As far as I know there's no way to quote the fields when exporting results to .csv using SSMS 2005 Express.

    0 讨论(0)
  • 2020-12-04 16:03

    set nocount on

    the quotes are there, use -w2000 to keep each row on one line.

    0 讨论(0)
  • 2020-12-04 16:04

    If it fits your requirements, you can use bcp on the command line if you do this frequently or want to build it into a production process.

    Here's a link describing the configuration.

    0 讨论(0)
提交回复
热议问题