Quantcast
Channel: BCP export to csv file
Viewing all articles
Browse latest Browse all 2

BCP export to csv file

$
0
0

 

I was following another thread looking for answers and tried a couple examples and I'm still getting errors.  I'm hoping someone can tell me what I'm doing wrong.

 

I'm looking to export a csv file from a stored procedure.  I'm not sure what the best way is, but I'm trying BCP.

 

Here are 2 sets of code I've tried:

 

bcp <tablename> out 'C:\STacy\ExportNew.csv' /U /P   /c /t

 

With this I get the error:  Cannot use the OUTPUT option when passing a constant to a stored procedure.

 

I also tried:

 

DECLARE @bcpCommand varchar(2000)

SET @bcpCommand = 'bcp <tablename> out
C:\STacy\ExportNew.csv -c -T -S @@servername'
 
EXEC master..xp_cmdshell @bcpCommand

 

with this, I get no error, But I'm using Query Analyzer and I'm getting an output that looks like: 

 usage: bcp {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
etc...

 

and I'm not getting any new ExportNew.csv file in my folder.  So I don't see that it is doing what I want it to do.

 

Also, if I use BCP, I'm going to need to select a specific query to be exported, not just the entire table.  I"m assuming that is possible, whether with a view or something, but I haven't seen an example yet for that.

 

Any help is very much appreciated.

Thank you,

Stacy

 

 


 


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images