

If character data is represented by Unicode wide characters, then a positive BCP_FMT_DATA_LEN parameter value represents the number of characters multiplied by the size, in bytes, of each character. The BCP_FMT_DATA_LEN value represents the count of bytes of data.

However, if, in addition to a positive BCP_FMT_DATA_LEN, a length indicator or terminator sequence is provided, the system determines the data length by using the method that results in the least amount of data being copied. If BCP_FMT_DATA_LEN is 0 or a positive value, the system uses BCP_FMT_DATA_LEN as the maximum data length. If BCP_FMT_DATA_LEN is SQL_VARLEN_DATA, the data type is an SQL Server character or binary type, and neither a length indicator nor a terminator sequence is specified, the system returns an error message.

If both a length indicator and a terminator sequence are supplied, bulk copy uses the one that results in the least amount of data being copied. If BCP_FMT_DATA_LEN is SQL_VARLEN_DATA, the system uses either the length indicator, if present, or a terminator sequence to determine the length of the data. For some columns, this could mean that a length/null indicator is generated to precede data on a copy from SQL Server, or that the indicator is expected in data copied to SQL Server.įor SQL Server character and binary data types, BCP_FMT_DATA_LEN can be SQL_VARLEN_DATA, SQL_NULL_DATA, 0, or some positive value.

Setting BCP_FMT_DATA_LEN to SQL_VARLEN_DATA indicates that the system should determine the length of data in each column. Setting BCP_FMT_DATA_LEN to SQL_NULL_DATA indicates that all values in the data file column are, or should be set to, NULL. It is the maximum length, in bytes, of this column's data in the user file, not including the length of any length indicator or terminator. Is the length in bytes of the data (column length) If more than one means of specifying a data file column length is used (such as an indicator and a maximum column length, or an indicator and a terminator sequence), bulk copy chooses the one that results in the least amount of data being copied.ĭata files generated by bulk copy when no user intervention adjusts the format of the data contain indicators when the column data can vary in length or the column can accept NULL as a value. Indicators appear in memory directly before any data, and in the data file directly before the data to which they apply. To specify default bulk copy indicator usage, set this parameter to SQL_VARLEN_DATA. Valid indicator length values are 0 (when using no indicator), 1, 2, or 4. It is the length, in bytes, of a length/null indicator within the column data. Is the length in bytes of the indicator (prefix). Otherwise, if the source column is decimal or numeric, the precision and scale of the source column are used. To specify the default data representation for the SQL Server data type, set this parameter to 0.įor a bulk copy out of SQL Server into a file, when BCP_FMT_TYPE is SQLDECIMAL or SQLNUMERIC, if the source column is not decimal or numeric, the default precision and scale are used. For example, you can specify a character string, ODBC type SQL_C_CHAR, using the SQLCHARACTER type specific to SQL Server. The BCP_FMT_TYPE parameter is enumerated by the SQL Server data type tokens in sqlncli.h, rather than the ODBC C data type enumerators. If different from the data type of the corresponding column in the database table, bulk copy converts the data if possible. Is the data type of this column in the user file. Property constants are defined in this table. Is the ordinal column number for which the property is being set. Is the bulk copy-enabled ODBC connection handle. When used as a target format, the data file is created using the column formats specified with bcp_setcolfmt. When used as a source format, bcp_setcolfmt specifies the format of an existing data file used as a data source of data in a bulk copy to a table in SQL Server. The bcp_setcolfmt function specifies the source or target format of the data in a user file. Each call to bcp_setcolfmt sets one column format attribute. It is used to set individual column format attributes. This function provides a flexible approach to specifying the column format in a bulk copy operation. bcp_setbulkmode can be used to specify more than one column format. In specifying the column collation, the bcp_setcolfmt function must be used. The bcp_setcolfmt function supersedes the bcp_colfmt.
