sql bcp导出到csv文件 [英] sql bcp export to csv file

查看:446
本文介绍了sql bcp导出到csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

我正在尝试将表的内容导出到csv文件.我尝试了以下代码,但无法找出我在做什么.

Hi friends,

I am trying to export the contents of a table to a csv file. I have tried the following code but cannot find out what I''m doing wrong.

declare @sql varchar(8000)
select @sql = 'bcp travelcatdata.dbo.communicator out 
''c:\datafiles\comm.txt'' -c -t, -T -S '+ @@servername
exec master..xp_cmdshell @sql



未创建该文件,并且在运行查询时,我在结果窗格中得到以下内容:



The file is not created and when I run the query I get the following in the results pane:

usage: bcp {dbtable | query} {in | out | queryout | format} datafile
  [-m maxerrors]            [-f formatfile]          [-e errfile]
  [-F firstrow]             [-L lastrow]             [-b batchsize]
  [-n native type]          [-c character type]      [-w wide character type]
  [-N keep non-text native] [-V file format version] [-q quoted identifier]
  [-C code page specifier]  [-t field terminator]    [-r row terminator]
  [-i inputfile]            [-o outfile]             [-a packetsize]
  [-S server name]          [-U username]            [-P password]
  [-T trusted connection]   [-v version]             [-R regional enable]
  [-k keep null values]     [-E keep identity values]
  [-h "load hints"]         [-x generate xml format file]
NULL




有人可以帮忙吗?

最好我想导出一个接受参数的存储过程的结果,但是一个表也可以.




Can anyone help please?

Preferably I would like to export the results of a stored procedure accepting parameters but a table would also do fine.

推荐答案

BCP示例 [
BCP examples[^]


taking resource from the above link I would suggest that you try removing the quotes from the destination file name

e.g.

declare @sql varchar(8000)
select @sql = 'bcp travelcatdata.dbo.communicator out c:\datafiles\comm.txt -c -t, -T -S '+ @@servername
exec master..xp_cmdshell @sql


这篇关于sql bcp导出到csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆