简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM