I need to store in a CSV file the result of a procedure.

I am using the following command:

Exec master..xp_cmdshell 'bcp "EXEC Database.dbo.StoredProcedure" queryout "\\workstatio\c$\usuario.csv" -F1 -SServername -E -c'

I need the result to be separated by column. How can I do this?

more ▼

asked Mar 03 '10 at 11:33 AM in Default

Felipe gravatar image

262 23 23 23

(comments are locked)
10|1200 characters needed characters left

1 answer: sort newest

If you mean separated by comma, then use the '-t ,' option.

The default without specifying is tab - same as saying '-t \t'

MSDN BOL reference here

more ▼

answered Mar 03 '10 at 11:48 AM

Kev Riley gravatar image

Kev Riley ♦♦
50.8k 43 49 76

I do not want to be separated by comma. I need every column of the stored procedure is in a different column in the CSV.
Mar 03 '10 at 11:56 AM Felipe
You will have to use a comma or tab seperated. A CSV stands for "comma seperated values"????
Mar 03 '10 at 12:00 PM sp_lock
I'm sorry I don't understand your question - could you show some data as an example?
Mar 03 '10 at 12:18 PM Kev Riley ♦♦
possibly a column inbetween each result column ... ???
Mar 03 '10 at 12:51 PM Fatherjack ♦♦
Simple. For example, my procedure returns 2 columns: Column A and Column B. In the CSV file, the first column should contain the result of Column A and the second column should contain the result of Column B. Do you understand?
Mar 03 '10 at 01:20 PM Felipe
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Mar 03 '10 at 11:33 AM

Seen: 1120 times

Last Updated: Mar 03 '10 at 12:00 PM