BCP Error: columns may be skipped only when copying into the Server

让人想犯罪 __ 提交于 2019-12-24 01:09:50

问题


When I issue this command (It looks silly but it works):

BCP "declare @colnames varchar(max); select @colnames=coalesce (@colnames+char(9), '') 
+ Column_Name from db.information_Schema.columns where table_name='table1' order by 
ordinal_position; select @colnames" 
     queryout Table1_Columns.tsv -S?? -U?? -P?? -f** -e**

I get this error:

[Microsoft][SQL Native Client]Host-file columns may be skipped only when copying into the Server

The format file is:

9.0
1
1 SQLCHAR 0 100 "\r\n" 1 Column_Names SQL_Latin1_General_CP1_CI_AS

Can someone tell me why I am getting this error?


回答1:


There's an active bug report for this: http://connect.microsoft.com/SQLServer/feedback/details/584001/bcp-table-out-with-format-file-does-not-work-if-file-specifies-less-columns-than-source-table.

One simple workaround would be to write the variable to a temporary table (not a #temptable, but rather a table that is temporary), and bcp out from that.



来源:https://stackoverflow.com/questions/23277065/bcp-error-columns-may-be-skipped-only-when-copying-into-the-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!