如下
--创建表
create table test_mamamiya( [by] int)
--插入数据
insert into test_mamamiya select 1
--BCP OUT正常
EXEC master..xp_cmdshell 'BCP "SELECT TOP 1 * FROM KSSC..test_mamamiya " queryout F:\test_mamamiya   -c -t"," -S"192.168.149.123" '--问题出在这里(因为test_mamamiya中的字段是BY,导致导入失败,请问该如何处理,论坛中没有搜索到相关的帖子)
EXEC master..xp_cmdshell 'bcp kssc..test_mamamiya  in F:\test_mamamiya -c -t"," -E -S"192.168.149.123" '--报错信息如下
开始复制...
SQLState = 37000, NativeError = 156
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]在关键字 'by' 附近有语法错误。

解决方案 »

  1.   

    EXEC master..xp_cmdshell 'bcp "kssc..test_mamamiya" in F:\test_mamamiya -c -t"," -E -S"192.168.149.123"
      

  2.   

    output
    ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    密码: 
    NULL
    开始复制...
    SQLState = 37000, NativeError = 156
    Error = [Microsoft][ODBC SQL Server Driver][SQL Server]在关键字 'by' 附近有语法错误。
    NULL
    已复制了 0 行。
    数据包的大小(字节): 4096
    时钟时间(毫秒): 共      1
    NULL加了“”一样还是报错的
      

  3.   

    字段是在表里面的,bcp in时如何转义