Saving results with headers in Sql Server Management Studio

后端 未结 10 2240
长发绾君心
长发绾君心 2020-12-13 01:35

I am using SQL Server Management Studio.

I wish to save the results of a query to an excel file.

I choose \"save as\" and then save to CSV file which I ca

相关标签:
10条回答
  • 2020-12-13 01:56

    Select your results by clicking in the top left corner, right click and select "Copy with Headers". Paste in excel. Done!

    0 讨论(0)
  • 2020-12-13 01:58

    I also face the same issue. When I used right click in the query window and select Query Options. But header rows does not show up in output CSV file.

    Then I logoff the server, login again and run the script. Then it worked.

    0 讨论(0)
  • 2020-12-13 02:05

    Got here when looking for a way to make SSMS properly escape CSV separators when exporting results.

    Guess what? - this is actually an option, and it is unchecked by default. So by default, you get broken CSV files (and may not even realize it, esp. if your export is large and your data doesn't have commas normally) - and you have to go in and click a checkbox so that your CSVs export correctly!

    To me, this seems like a monumentally stupid design choice and an apt metaphor for Microsoft's approach to software in general ("broken by default, requires meaningless ritualistic actions to make trivial functionality work").

    But I will gladly donate $100 to a charity of respondent's choice if someone can give me one valid real-life reason for this option to exist (i.e., an actual scenario where it was useful).

    0 讨论(0)
  • 2020-12-13 02:05

    In SQL Server 2014 Management Studio the setting is at:

    Tools > Options > Query Results > SQL Server > Results to Text > Include column headers in the result set.

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