A wrapper for a system call to the bcp utility which writes a SQL Server table or query (T-SQL) to a file.

bcpExport(
  file,
  connectargs,
  table,
  query,
  fieldterminator = "\t",
  rowterminator = ifelse(.Platform$OS.type == "windows", "\r\n", "\n"),
  bcpOptions = list("-c", "-b", 1000, "-a", 4096, "-m", 10),
  ...
)

Arguments

file

output file name

connectargs

named list of connection arguments. See makeConnectArgs.

table

name of the source table when exporting from SQL Server

query

Transact-SQL query that returns a result set. Ignored if table is specified.

fieldterminator

character separator for columns

rowterminator

character separator for rows--new lines

bcpOptions

list of additional options to pass to the bcp utility. See details.

...

arguments to pass system2

Value

No return value. Operations from bcp are printed to console; see ... to redirect output

Details

The bcpOptions allows the user to include additional arguments for the call to system2. Please refer to https://learn.microsoft.com/en-us/sql/tools/bcp-utility. The default options are set to the defaults for bcp CLI. -b refers to number of rows to write at a time; 10,000 to 50,000 is a starting recommendation. -a refers to size of packets to be sent in bytes. -e refers to the maximum number of errors before failure.