SQL Server – How to Terminate BCP Output with Specific String and Newline

sql server

I'm trying to terminate each row in BCP output with a specific string along with newline. Neither of these work:

  • -r"terminator_string\n"';
  • -r"terminator_string"+\n';

Any suggestions?

For an idea of the overall problem, see https://stackoverflow.com/questions/23329028/outofmemory-exception-when-reading-and-replacing-strings-with-streamreader-and-s

Best Answer

Use the ASCII codes of the characters you want to match (without the 0x prefix).

For example to match A (char hex 41) + LineFeed (char hex 0A) do this:

-r "410A"

This seems to be undocumented. See my blog here for more info: http://kejser.org/databases/bulk-insert-with-linux-line-endings/