Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sql Query results to CSV to a specified file path after stored procedure execution

I'm trying to execute a stored procedure (which i know works) in T-SQL that then gets those results into a CSV file and puts that file into a directory. I'm not sure how to formulate that query, exactly though. Here's what i've tried thus far to no avail:

EXECUTE CLR_ExportQueryToCSV @QueryCommand = 'execute databaseName.dbo.StoredProcedureName',
                          @FilePath = 'C:\Directory',
                          @FileName = '\FileToExport.csv',
                          @IncludeHeaders = 1

I realize CLR_ExportQueryToCSV doesn't exist. Is there any system stored procedure that will do what i'm wanting?

like image 560
user1789573 Avatar asked Dec 05 '25 18:12

user1789573


1 Answers

bcp "SELECT Col1,Col2,Col3 FROM MyDatabase.dbo.MyTable" queryout "D:\MyTable.csv" -c -t , -S SERVERNAME -T

docs

like image 157
JGFMK Avatar answered Dec 08 '25 08:12

JGFMK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!