2

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Dom
  • 71
  • 1
  • 2
  • 6

1 Answers1

2

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.