Reputation:
I am using SSMS and trying to export a query to a text file using T-SQL (I know there are options in the tool itself to do this, but I need this code for a stored procedure).
I found examples but none of them seem to work and each gives a different error message:
EXEC xp_cmdshell 'bcp "SELECT * FROM [REPORT_ReviewStatus]" queryout "\\sd-eefx-5586\Report Outputs\REPORT_H75_ReviewStatus.txt" -T -c'
The above gives me an error about:
So I try it using "Out"
EXEC xp_cmdshell 'bcp "SELECT * FROM [REPORT_ReviewStatus]" out "\\sd-eefx-5586\Report Outputs\REPORT_H75_ReviewStatus.txt" -T -c'
This gives me the following errors:
What am I doing wrong? How can I use BCP for this, or is there something else to do that doesn't use SSIS (I will do this if necessary, but would like to avoid it if possible)
Upvotes: 0
Views: 2144
Reputation: 11
I used a similar query that works but I wrote EXEC MASTER..xp_cmdshell
instead of what you have EXEC xp_cmdshell
Upvotes: 1