I am testing SQL Server on Linux. I am trying to output a table from SQL Server to a file. Since xp_cmdshell is not available on Linux I cannot use BCP directly from SQL Server Management Studio. How can I write to file using SQL Server Management Studio?
Asked
Active
Viewed 867 times
0
-
Maybe wait a little while MS will provide SQLAgent and then do it via Job. – Slava Murygin Jan 30 '17 at 23:37
1 Answers
0
If you just need the results of your query in your Windows machine, you can always write to file from SSMS by selecting the "Results to File" button, or pressing Ctrl-Shift-F.
If you need the file to be in a specific format, you can go to Tools>Options>Query Results>SQL Server>Results to Text and then select your desired format on the top-right corner of the window.
Let me know if this helps!

Luis Bosquez
- 386
- 2
- 11
-
Unfortunately this does not help me much. I would like to have a stored procedure that can save contents of a given table to a file. I used to do that a lot using xp_cmdshell. – smucha Nov 29 '16 at 11:49
-
I understand now. One thing you can do is create a script that uses SQLCMD to run a query and output the results to a file: `$ sqlcmd -S your_server -U sa -P your_password -Q "SELECT * FROM test_table" -o your_output_file.txt` – Luis Bosquez Dec 08 '16 at 18:02