Getting bcp.exe to escape terminators

后端 未结 4 1838
轮回少年
轮回少年 2021-01-17 14:41

I need to export some data using SQL Server 2000\'s BCP utility. Sometimes my data contains characters, such as \\t and \\n, that I need to use as column and row terminator

4条回答
  •  借酒劲吻你
    2021-01-17 14:59

    Totally agree with you: escaping should be an option. "You can't have data with tabs or newlines" is the silliest thing I have ever heard.

    Here is a possible solution:

    1. use the -r option to set a different line terminator. Something
      unlikely to be present in your data (#!#$#%#). I think you can use multiple
      characters, so that makes it easier.
    2. Open your data file in sed, a capable text editor, or write a script - and replace any \n and \t character with their escaped equivalents (\\n and \\t). Finally replace your line terminator with \n and you should be good.
    3. I think the same thing should apply to using -t for field terminators

    Take a look at this article for more information.

提交回复
热议问题